Hello. When I was playing with a code I received a message:
BUG: trying to assign Array(SomeClass::InnerClass(UInt16)) <- Array(SomeClass::InnerClass(T)) (Exception)
from ???
[… dupes skipped …]
from ???
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues
The code to reproduce:
class SomeClass(T)
class InnerClass(T)
end
@foo = [] of InnerClass(T)
end
class SomeClassDesc(T) < SomeClass(T)
class SomeClass::InnerClass(T)
end
end
foo = SomeClassDesc(UInt16).new
OS:
Debian GNU/Linux 9.5 (stretch)
Crystal version:
Crystal 0.25.1 [b782738ff] (2018-06-27)
LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
The bug also can be reproduced on master branch with a detailed backtrace:
Crystal 0.25.1+86 [d454f6973] (2018-08-04)
LLVM: 4.0.1
Default target: x86_64-pc-linux-gnu
BUG: trying to assign Array(SomeClass::InnerClass(UInt16)) <- Array(SomeClass::InnerClass(T)) (Exception)
from /tmp/crystal/src/compiler/crystal/codegen/cast.cr:281:5 in 'assign_distinct'
from /tmp/crystal/src/compiler/crystal/codegen/cast.cr:85:7 in 'assign'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:1843:11 in 'run_instance_vars_initializers_non_recursive'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:1809:7 in 'run_instance_vars_initializers'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:1814:9 in 'run_instance_vars_initializers'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:1808:7 in 'run_instance_vars_initializers'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:1794:7 in 'allocate_aggregate'
from /tmp/crystal/src/compiler/crystal/codegen/primitives.cr:414:5 in 'codegen_primitive_allocate'
from /tmp/crystal/src/compiler/crystal/codegen/primitives.cr:23:15 in 'codegen_primitive'
from /tmp/crystal/src/compiler/crystal/codegen/call.cr:403:7 in 'codegen_call'
from /tmp/crystal/src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
from /tmp/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:2049:7 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:928:9 in 'codegen_assign'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:892:7 in 'visit'
from /tmp/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:2049:7 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:592:9 in 'visit'
from /tmp/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:2049:7 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/fun.cr:142:9 in 'codegen_fun'
from /tmp/crystal/src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
from /tmp/crystal/src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
from /tmp/crystal/src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
from /tmp/crystal/src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
from /tmp/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:2049:7 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:928:9 in 'codegen_assign'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:892:7 in 'visit'
from /tmp/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:2049:7 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:592:9 in 'visit'
from /tmp/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:2049:7 in 'accept'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:65:7 in 'codegen'
from /tmp/crystal/src/compiler/crystal/codegen/codegen.cr:63:5 in 'codegen:debug:single_module'
from /tmp/crystal/src/compiler/crystal/compiler.cr:22:7 in 'codegen'
from /tmp/crystal/src/compiler/crystal/compiler.cr:145:16 in 'compile'
from /tmp/crystal/src/compiler/crystal/command.cr:260:7 in 'compile'
from /tmp/crystal/src/compiler/crystal/command.cr:179:14 in 'run_command'
from /tmp/crystal/src/compiler/crystal/command.cr:87:7 in 'run'
from /tmp/crystal/src/compiler/crystal/command.cr:48:5 in 'run'
from /tmp/crystal/src/compiler/crystal/command.cr:47:3 in 'run'
from /tmp/crystal/src/compiler/crystal.cr:8:1 in '__crystal_main'
from /tmp/crystal/src/crystal/main.cr:104:5 in 'main_user_code'
from /tmp/crystal/src/crystal/main.cr:93:7 in 'main'
from /tmp/crystal/src/crystal/main.cr:133:3 in 'main'
from __libc_start_main
from _start
from ???
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues
Simplified example (carc.in link here):
class InnerClass(T)
end
class SomeClass(T)
@foo = [] of InnerClass(T)
end
class NewClass(T) < SomeClass(T)
end
foo = NewClass(UInt16).new
This is probably another generics issue.
The code you provided is simpler and gives same result as mine (on both 0.25.1 and master).
Thank you.
Still being reproduced on
Crystal 0.27.0 [c9d1eef8f] (2018-11-01)
LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
Probably related: https://play.crystal-lang.org/#/r/8rzu
abstract struct Comparison(T)
getter type : T.class = T
def initialize(@value : T); end
end
struct GreaterThan(T) < Comparison(T)
end
pp GreaterThan(Int32).new 1 # => BUG: trying to assign Int32.class <- T.class (Exception)
Just ran into this one on 0.35.1
My minimal reproduction:
class Dog(T)
getter friends = Array(Dog(T)).new
end
class GermanShepherd(T) < Dog(T)
end
GermanShepherd(String).new
Most helpful comment
Just ran into this one on 0.35.1
My minimal reproduction: