Description
Bug Report
BUG: trying to downcast (String | Nil) (Crystal::NilableType) <- String (Crystal::NonGenericClassType) (Exception)
I've put a repository with the reproduction at https://github.com/veridit/crystal-compiler-bug
To run it
git clone https://github.com/veridit/crystal-compiler-bug
cd crystal-compiler-bug
shards build statbus
I've not seen the same error in existing bugs, but I notice that #15200 mentions a Crystal::NonGenericClassType
but it starts from a Crystal::VirtualType
and not a Crystal::NilableType
.
I've been unable to make a minimal reproduction, but started at https://github.com/veridit/crystal-compiler-bug/blob/master/src/minimal_test_case.cr by trying to use the same setup of class, instance variable, method variables, scopes, branches.
It seems there is more to it than that.
I have identified the line that triggers the bug https://github.com/veridit/crystal-compiler-bug/blob/master/src/statbus.cr#L1611:
STDOUT.puts output if @debug && output && !output.empty?
vs. this line that does not trigger the bug
STDOUT.puts output if @debug && !output.empty?
I'm using
Crystal 1.15.0 (2025-01-10)
LLVM: 19.1.6
Default target: aarch64-apple-darwin24.1.0
I have not yet tried with building the latest Crystal from GitHub to test.