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
#10267 disallows unions in type restrictions that refer to more than one free var. However, some unions with multiple free vars are in fact solvable:
deffoo(x : T, y : U, z : T|U) forallT, Uend
foo(1, 'a', 1) # okay, T = Int32, U = Char
foo(1, 'a', 'a') # okay, T = Int32, U = Char
foo(1, 1, 1) # okay, T = Int32, U = Int32
That PR also doesn't raise on free vars that aren't directly under the union type, so the following oddity happens on 0.36.1: (contrast this to #8973 and #10370)
deffoo(x : Array(T) |T) forallTTenddefbar(x : T|Array(T)) forallTTend
foo([1]) # => Int32
bar([1]) # => Array(Int32)
foo([[1]] || [[1], 1]) # => (Array(Int32) | Int32)# note that typeof(x) <= (Array(T) | T) is false in this case; somewhere# Crystal considers Array(X | Y) to be distributive over the union, turning# Array(Array(Int32) | Int32) into Array(Array(Int32)) | Array(Int32)
bar([[1]] || [[1], 1]) # => (Array(Int32) | Int32)
Until we figure out how to unify those kinds of free vars, I think we should disallow any union type restrictions that use more than one free var, whether they are identical or not, and whether they appear as generic type / metaclass arguments or not.
The text was updated successfully, but these errors were encountered:
#10267 disallows unions in type restrictions that refer to more than one free var. However, some unions with multiple free vars are in fact solvable:
That PR also doesn't raise on free vars that aren't directly under the union type, so the following oddity happens on 0.36.1: (contrast this to #8973 and #10370)
Until we figure out how to unify those kinds of free vars, I think we should disallow any union type restrictions that use more than one free var, whether they are identical or not, and whether they appear as generic type / metaclass arguments or not.
The text was updated successfully, but these errors were encountered: