crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.46k stars 1.62k forks source link

BUG: called create_llvm_type for ValueType (Exception) #8968

Open Blacksmoke16 opened 4 years ago

Blacksmoke16 commented 4 years ago

Came up while debugging #8967.

https://play.crystal-lang.org/#/r/8sai

abstract struct Constraint
end

abstract struct AbstractComparison(ValueType) < Constraint
  getter value : ValueType

  def initialize(@value : ValueType)
  end
end

struct GreaterThan(ValueType) < AbstractComparison(ValueType)
end

struct NotBlank < Constraint
end

def validate(value : _, constraint : AbstractComparison) : Nil
  pp typeof(constraint.value)
end

def validate(value : _, constraint : Constraint) : Nil
end

constraints = [GreaterThan.new value: 10] || Array(Constraint).new

validate 15, constraints.first
BUG: called create_llvm_type for ValueType (Exception)
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_typer.cr:258:7 in 'create_llvm_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_typer.cr:88:37 in 'llvm_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_typer.cr:378:9 in 'llvm_embedded_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_typer.cr:312:32 in 'create_llvm_struct_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_typer.cr:265:44 in 'llvm_struct_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_typer.cr:140:20 in 'create_llvm_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_typer.cr:88:37 in 'llvm_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/unions.cr:34:28 in 'create_llvm_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_typer.cr:90:26 in 'llvm_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_typer.cr:84:5 in 'llvm_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_builder_helper.cr:182:5 in 'llvm_type'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/llvm_builder_helper.cr:179:23 in 'cast_to_pointer'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/unions.cr:111:7 in 'downcast_distinct_union_types'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/cast.cr:425:7 in 'downcast_distinct'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/cast.cr:293:15 in 'downcast'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/codegen.cr:1152:17 in 'visit'
  from /home/george/dev/git/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/codegen.cr:2162:7 in 'accept'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/call.cr:102:7 in 'prepare_call_args_non_external'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/call.cr:59:7 in 'prepare_call_args'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/call.cr:23:26 in 'visit'
  from /home/george/dev/git/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/codegen.cr:2162:7 in 'accept'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/call.cr:382:11 in 'codegen_dispatch'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/call.cr:15:7 in 'visit'
  from /home/george/dev/git/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/codegen.cr:2162:7 in 'accept'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/codegen.cr:626:9 in 'visit'
  from /home/george/dev/git/crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/codegen.cr:2162:7 in 'accept'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/codegen.cr:67:7 in 'codegen'
  from /home/george/dev/git/crystal/src/compiler/crystal/codegen/codegen.cr:65:5 in 'codegen:debug:single_module'
  from /home/george/dev/git/crystal/src/compiler/crystal/compiler.cr:22:7 in 'codegen'
  from /home/george/dev/git/crystal/src/compiler/crystal/compiler.cr:170:16 in 'compile'
  from /home/george/dev/git/crystal/src/compiler/crystal/command.cr:280:3 in 'compile'
  from /home/george/dev/git/crystal/src/compiler/crystal/command.cr:196:14 in 'run_command'
  from /home/george/dev/git/crystal/src/compiler/crystal/command.cr:111:7 in 'run'
  from /home/george/dev/git/crystal/src/compiler/crystal/command.cr:49:5 in 'run'
  from /home/george/dev/git/crystal/src/compiler/crystal/command.cr:48:3 in 'run'
  from /home/george/dev/git/crystal/src/compiler/crystal.cr:14:1 in '__crystal_main'
  from /home/george/dev/git/crystal/src/crystal/main.cr:105:5 in 'main_user_code'
  from /home/george/dev/git/crystal/src/crystal/main.cr:91:7 in 'main'
  from /home/george/dev/git/crystal/src/crystal/main.cr:114: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
Blacksmoke16 commented 4 years ago

Duplicate of https://github.com/crystal-lang/crystal/issues/8551

Blacksmoke16 commented 3 years ago

Reopening as this seems to be a different issue not resolved via #10729.

HertzDevil commented 3 years ago

Reduced:

class Foo
end

class Bar(T1) < Foo
  def initialize(@value : T1)
  end

  def value
    @value
  end
end

class Baz(T2) < Bar(T2)
  def initialize(@value : T2)
  end
end

Bar.new(10).as(Foo).as(Bar).value
BUG: called create_llvm_type for T2 (Exception)
  from src/compiler/crystal/codegen/llvm_typer.cr:254:7 in 'create_llvm_type'
  from src/compiler/crystal/codegen/llvm_typer.cr:88:37 in 'llvm_type'
  from src/compiler/crystal/codegen/unions.cr:34:28 in 'create_llvm_type'
  from src/compiler/crystal/codegen/llvm_typer.cr:90:26 in 'llvm_type'
  from src/compiler/crystal/codegen/llvm_typer.cr:84:5 in 'llvm_type'
  from src/compiler/crystal/codegen/llvm_typer.cr:429:7 in 'llvm_return_type'
  from src/compiler/crystal/codegen/codegen.cr:182:18 in 'initialize'
  from src/compiler/crystal/codegen/codegen.cr:171:5 in 'new:single_module:debug'
  from src/compiler/crystal/codegen/codegen.cr:66:7 in 'codegen'
  from src/compiler/crystal/codegen/codegen.cr:65:5 in 'codegen:debug:single_module'
  from src/compiler/crystal/progress_tracker.cr:22:7 in 'codegen'
  from src/compiler/crystal/compiler.cr:172:16 in 'compile'
  from src/compiler/crystal/command.cr:296:3 in 'compile'
  from src/compiler/crystal/command.cr:208:14 in 'run_command'
  from src/compiler/crystal/command.cr:117:7 in 'run'
  from src/compiler/crystal/command.cr:49:5 in 'run'
  from src/compiler/crystal/command.cr:48:3 in 'run'
  from src/compiler/crystal.cr:11:1 in '__crystal_main'
  from src/crystal/main.cr:110:5 in 'main_user_code'
  from src/crystal/main.cr:96:7 in 'main'
  from src/crystal/main.cr:119:3 in 'main'
  from __libc_start_main
  from _start
  from ???

Calling .@value instead of .value produces BUG: called create_llvm_type for T1 (Exception) instead.