Skip to content

Compiler crash when passing-through a generic type into an implicit initialization of an Array instance var #4753

@Papierkorb

Description

Hi,

While working on a shard I came across a compiler crash bug.

Platform: ArchLinux x64, Crystal 0.23.1 (2017-07-17) LLVM 4.0.1

The following code crashes at compile-time:

class Foo(T)
  @collected = [ ] of T # <- The issue
end

class Bar(T) < Foo(T)
end

bar = Bar(Int32).new # Triggers the issue
# foo = Foo(Int32).new # This alone would be fine however!

However, if we write it without the implicit initialization to an empty array like this:

class Foo(T)
  # @collected : Array(T) # Makes no difference if this is there or not.

  def initialize # Writing the same thing, but explicit
    @collected = [] of T # Works fine!
    # @collected = Array(T).new # Works fine too!
  end
end

class Bar(T) < Foo(T)
end

bar = Bar(Int32).new # Works fine!

It works fine! So, the issue only seems to occurs for a passed-through T, which is then applied to an implicit initialization. I haven't tried the Hash short-hand though.

Compiler output

BUG: called create_llvm_type for T
0x7a1abb: *CallStack::unwind:Array(Pointer(Void)) at ??
0x14cf0b5: create_llvm_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 299:7
0x14ca0cd: llvm_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 92:26
0x14cab4e: llvm_embedded_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 419:9
0x14ca975: create_llvm_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 174:22
0x14c9940: llvm_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 92:26
0x14cab4e: llvm_embedded_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 419:9
0x14cd059: create_llvm_struct_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 353:32
0x14cbe93: llvm_struct_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 308:33
0x14cb5aa: create_llvm_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 142:20
0x14c9b93: llvm_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 92:26
0x14c8547: llvm_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 86:5
0x14c850b: llvm_return_type at .../crystal/src/compiler/crystal/codegen/llvm_typer.cr 468:7
0x146351b: llvm_return_type at .../crystal/src/compiler/crystal/codegen/llvm_builder_helper.cr 131:5
0x1488a8f: codegen_fun_signature_non_external at .../crystal/src/compiler/crystal/codegen/fun.cr 251:24
0x148757a: codegen_fun_signature at .../crystal/src/compiler/crystal/codegen/fun.cr 209:7
0x1486a23: codegen_fun at .../crystal/src/compiler/crystal/codegen/fun.cr 80:14
0x148c2e8: codegen_fun at .../crystal/src/compiler/crystal/codegen/fun.cr 51:3
0x148bbd1: target_def_fun at .../crystal/src/compiler/crystal/codegen/fun.cr 8:54
0x149db5b: codegen_call at .../crystal/src/compiler/crystal/codegen/call.cr 406:12
0x149495b: visit at .../crystal/src/compiler/crystal/codegen/call.cr 35:7
0xb5a82f: accept at .../crystal/src/compiler/crystal/syntax/visitor.cr 27:12
0x14a5e4b: run_instance_vars_initializers_non_recursive at .../crystal/src/compiler/crystal/codegen/codegen.cr 1813:11
0x14a56a2: run_instance_vars_initializers at .../crystal/src/compiler/crystal/codegen/codegen.cr 1782:7
0x14a5748: run_instance_vars_initializers at .../crystal/src/compiler/crystal/codegen/codegen.cr 1786:9
0x14a5662: run_instance_vars_initializers at .../crystal/src/compiler/crystal/codegen/codegen.cr 1780:7
0x14a4f2f: allocate_aggregate at .../crystal/src/compiler/crystal/codegen/codegen.cr 1766:7
0x14a48e7: codegen_primitive_allocate at .../crystal/src/compiler/crystal/codegen/primitives.cr 409:5
0x149e724: codegen_primitive at .../crystal/src/compiler/crystal/codegen/primitives.cr 23:15
0x149daf5: codegen_call at .../crystal/src/compiler/crystal/codegen/call.cr 401:7
0x149495b: visit at .../crystal/src/compiler/crystal/codegen/call.cr 35:7
0xb5a82f: accept at .../crystal/src/compiler/crystal/syntax/visitor.cr 27:12
0x147d231: accept at .../crystal/src/compiler/crystal/codegen/codegen.cr 1986:7
0x148d526: codegen_assign at .../crystal/src/compiler/crystal/codegen/codegen.cr 902:9
0x148cf4a: visit at .../crystal/src/compiler/crystal/codegen/codegen.cr 866:7
0xb5a24c: accept at .../crystal/src/compiler/crystal/syntax/visitor.cr 27:12
0x147d231: accept at .../crystal/src/compiler/crystal/codegen/codegen.cr 1986:7
0x148c489: visit at .../crystal/src/compiler/crystal/codegen/codegen.cr 574:9
0xb59b12: accept at .../crystal/src/compiler/crystal/syntax/visitor.cr 27:12
0x147d231: accept at .../crystal/src/compiler/crystal/codegen/codegen.cr 1986:7
0x14872e9: codegen_fun at .../crystal/src/compiler/crystal/codegen/fun.cr 140:9
0x148c2e8: codegen_fun at .../crystal/src/compiler/crystal/codegen/fun.cr 51:3
0x148bbd1: target_def_fun at .../crystal/src/compiler/crystal/codegen/fun.cr 8:54
0x149db5b: codegen_call at .../crystal/src/compiler/crystal/codegen/call.cr 406:12
0x149495b: visit at .../crystal/src/compiler/crystal/codegen/call.cr 35:7
0xb5a82f: accept at .../crystal/src/compiler/crystal/syntax/visitor.cr 27:12
0x147d231: accept at .../crystal/src/compiler/crystal/codegen/codegen.cr 1986:7
0x148d526: codegen_assign at .../crystal/src/compiler/crystal/codegen/codegen.cr 902:9
0x148cf4a: visit at .../crystal/src/compiler/crystal/codegen/codegen.cr 866:7
0xb5a24c: accept at .../crystal/src/compiler/crystal/syntax/visitor.cr 27:12
0x147d231: accept at .../crystal/src/compiler/crystal/codegen/codegen.cr 1986:7
0x148c489: visit at .../crystal/src/compiler/crystal/codegen/codegen.cr 574:9
0xb59b12: accept at .../crystal/src/compiler/crystal/syntax/visitor.cr 27:12
0x905dcf: codegen at .../crystal/src/compiler/crystal/codegen/codegen.cr 65:7
0x905d58: codegen:debug:single_module:expose_crystal_main at .../crystal/src/compiler/crystal/codegen/codegen.cr 63:5
0x13f5783: codegen at .../crystal/src/compiler/crystal/compiler.cr 22:7
0x13f7ef3: compile at .../crystal/src/compiler/crystal/compiler.cr 139:16
0x15377d9: compile at .../crystal/src/compiler/crystal/command.cr 264:7
0x8c97d2: run_command at .../crystal/src/compiler/crystal/command.cr 194:14
0x8c5b53: run at .../crystal/src/compiler/crystal/command.cr 105:11
0x8c517b: run at .../crystal/src/compiler/crystal/command.cr 49:5
0x8c513b: run at .../crystal/src/compiler/crystal/command.cr 48:3
0x77128b: __crystal_main at .../crystal/src/compiler/crystal.cr 8:1
0x785ed9: main at .../crystal/src/main.cr 12:15
0x7fb94936843a: __libc_start_main at ??
0x7703aa: _start at ??
0x0: ??? at ??

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

Thanks.

Metadata

Assignees

No one assigned

    Labels

    kind:bugA bug in the code. Does not apply to documentation, specs, etc.topic:compiler

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions