crystal-lang / crystal

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

Compiler bug when Hash block always raises #13717

Open carlhoerberg opened 1 year ago

carlhoerberg commented 1 year ago

This is stupid code of course, but still, Crystal raises an error instead of pointing out the error.

crystal eval 'Hash(String, String).new { |h, k| h[k] = raise "" }'
Cast from Nil to Crystal::ProcInstanceType failed, at /tmp/crystal/src/compiler/crystal/semantic/bindings.cr:535:7:535 (TypeCastError)
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '??'
  from crystal in '__crystal_main'
  from crystal in 'main'
  from /lib64/libc.so.6 in '??'
  from /lib64/libc.so.6 in '__libc_start_main'
  from crystal in '_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
 ✗ crystal -v
Crystal 1.9.2 [1908c81] (2023-07-19)

LLVM: 16.0.6
Default target: x86_64-redhat-linux-gnu
HertzDevil commented 1 year ago

Reduced:

def foo(block)
end

def bar(&block : -> String)
  foo block
end

bar { asdf(while true; end) }