You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While writing #9964 I was surprised to find that the -> literal grabs surrounding commas even inside a generic type list, so all types to the left become Proc arguments and the types after the -> become the return type:
(While typeof itself can appear inside a type name, its own arguments are Crystal expressions, not types, so the only parenthesized argument lists that can appear in a type name are generics.)
3 out of those 4 cases mandate parentheses around the -> to make the types 2-tuples:
I find this rather counterintuitive; I think the type grammar would look better if -> only grabs one argument inside a generic type list when there are no extra parentheses:
Tuple(Int32, Bool->) # => Tuple(Int32, Proc(Bool, Nil))Tuple(Int32, Bool->String) # => Tuple(Int32, Proc(Bool, String))Tuple(->Int32, Bool) # => Tuple(Proc(Int32), Bool)Tuple(String->Int32, Bool) # => Tuple(Proc(String, Int32), Bool)# the 1-tuples from the original snippet would then require double parenthesesTuple((Int32, Bool->)) # => Tuple(Proc(Int32, Bool, Nil))Tuple((Int32, Bool->String)) # => Tuple(Proc(Int32, Bool, String))
The text was updated successfully, but these errors were encountered:
I think this is a good change and it will solve the issue of sometimes having to surround some expressions in parentheses to avoid accidentally specifying a proc type with multiple arguments.
That said, that syntax is used a lot in C bindings and it will be very annoying to always surround things with parentheses.
While writing #9964 I was surprised to find that the
->
literal grabs surrounding commas even inside a generic type list, so all types to the left becomeProc
arguments and the types after the->
become the return type:(While
typeof
itself can appear inside a type name, its own arguments are Crystal expressions, not types, so the only parenthesized argument lists that can appear in a type name are generics.)3 out of those 4 cases mandate parentheses around the
->
to make the types 2-tuples:I find this rather counterintuitive; I think the type grammar would look better if
->
only grabs one argument inside a generic type list when there are no extra parentheses:The text was updated successfully, but these errors were encountered: