crystal-lang / crystal

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

Compiler error - BUG: `` at has no type (Exception) #7017

Open proxima opened 6 years ago

proxima commented 6 years ago

Commenting out the line c.receive makes the compiler not complain.

class Test
  @login : Channel(String) | Nil = nil

  def run
    spawn do
      @login.try do |c|
        loop do
          c.receive
        end
      end
    end
  end
end

t = Test.new
t.run
Crystal 0.26.1 [391785249] (2018-08-27)

LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
bew commented 6 years ago

Reduced:

# Must be generic
abstract class Foo(T)
  def method
    method_impl # The call is important
  end
end

# Makes no difference
#class Bar(T) < Foo(T)
#  def method_impl
#  end
#end

class Test
  @var : Foo(Int32)? = nil

  def method
    @var.try &.method
  end
end

Test.new.method

No idea what's going on though..

RX14 commented 6 years ago

https://carc.in/#/r/5f2g

straight-shoota commented 5 years ago

Debug backtrace:

BUG: `` at  has no type (Exception)
  from src/compiler/crystal/semantic/bindings.cr:13:45 in 'type'
  from src/compiler/crystal/codegen/call.cr:453:15 in 'inline_call_return_value'
  from src/compiler/crystal/codegen/call.cr:428:7 in 'try_inline_call'
  from src/compiler/crystal/codegen/call.cr:394:8 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:68:5 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/call.cr:286:13 in 'codegen_call_with_block'
  from src/compiler/crystal/codegen/call.cr:32:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/call.cr:378:11 in 'codegen_dispatch'
  from src/compiler/crystal/codegen/call.cr:15:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/fun.cr:144:9 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:605:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:65:7 in 'codegen'
  from src/compiler/crystal/codegen/codegen.cr:63:5 in 'codegen:debug:single_module'
  from src/compiler/crystal/compiler.cr:22:7 in 'codegen'
  from src/compiler/crystal/compiler.cr:153:16 in 'compile'
straight-shoota commented 5 years ago

@bcardiff This doesn't seem to be related to generics. In fact, the error is the same with a non-generic type. I suppose it has to do with there being no valid concrete ancestor of Foo and #method doesn't seem to be semantically analysed and it only fails at codegen.

bcardiff commented 5 years ago

You are probably right, it's just that all the examples so far were with generics...

straight-shoota commented 5 years ago

Yep. @bew stated it needed to be generic, but it doesn't.

Maybe related: #6996