-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Compiler bug in Array#unshift #10211
Comments
Same here on macOS (10.14.6):
|
Reduced: class Gen(T)
end
ptr = Pointer(Gen(Int32 | Char)).malloc(1_u64)
ptr.value = Gen(Int32).new The above shouldn't compile. It's the same with every generic type. I think for Pointer specially we need to match generic in an invariant way. |
Hi, thanks for the quick response and detailed explanation. For others that may stumble on this: I tried a few workarounds and found that I can nudge the compiler in the right direction. I aimed to do: header : Array(String|Int32) = %w{Name Size} # Error: type must be Array(String | Int32), not Array(String) Instead: header : Array(String|Int32) = ["Name", "Size"] # Error: type must be Array(String | Int32), not Array(String)
header : Array(String|Int32) = ["Name", Int32.new(5)] # OK (but not useful for me)
header : Array(String|Int32) = ["Name", "Size"].as(Array(String|Int32)) # Error: can't cast Array(String) to Array(String | Int32)
header : Array(String|Int32) = ["Name".as(String|Int32), "Size"] # OK
header : Array(String|Int32) = [] of (String|Int32) << "Name" << "Size" # OK
header : Array(String|Int32) = [] of (String|Int32) + %w{Name Size} # OK
header = [] of (String|Int32) + %w{Name Size} # OK |
@mcarpenter You should just be able to do |
I can drop the type restriction too: header = ["Name", "Size"] of String|Int32 Kind of a shame that doesn't work with |
Description
I have a table (matrix, 2D array) of type
Array(Array(Int32 | String))
. If I#unshift
a row of typeArray(String)
onto it then the compiler crashes withFunction return type does not match operand type of return inst!
. Running 0.35.1 from the official PPA (Ubuntu repo) on Ubuntu 18.The error appears to be related to the union type: it goes away with
Array(Array(String))
at least. Other methods (<<
,+
) seem to be okay.Reproducer
foo.cr
:Version and platform information
The text was updated successfully, but these errors were encountered: