Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix type names for generic instances with empty splat type vars #13189

Conversation

HertzDevil
Copy link
Contributor

@HertzDevil HertzDevil commented Mar 15, 2023

Fixes an issue where if a generic type has at least one splat type variable and one non-splat type variable, and a generic instance has zero type arguments corresponding to the splat, that instance's type name includes an extra comma:

module Foo(A, *B)
  {% Foo(Int32) %} # => Foo(Int32, )
end

module Bar(*A, B)
  {% Bar(Int32) %} # => Bar(, Int32)
end

module Baz(A, *B, C)
  {% Baz(Int32, String) %} # => Baz(Int32, , String)
end

In particular, if the splat is not the last variable of the generic type, the resulting type name is syntactically invalid. This shows up everywhere, from macro interpolations like above to Class#name and error messages.

Tuple and Proc, the only two built-in variadic generics, override Crystal::Type#to_s_with_options, so they are immune from this.

@HertzDevil HertzDevil added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:generics labels Mar 15, 2023
@straight-shoota straight-shoota added this to the 1.8.0 milestone Mar 15, 2023
@straight-shoota straight-shoota merged commit 877df28 into crystal-lang:master Mar 16, 2023
@HertzDevil HertzDevil deleted the bug/type-name-empty-splat-type-var branch March 25, 2023 08:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:generics
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants