Open
Description
The following program fails in the interpreter:
require "option_parser"
opt_parser = OptionParser.parse do |parser|
parser.on("-h", "--help", "Show help") do
puts parser
exit
end
end
parser = ""
I think, it is because the parser
variable is used both in the block, but also reused as a different type (outside of the block). In the normal compiler, it works.
$ crystal i example.cr
Crystal interpreter 1.16.0-dev [9b7fd8dc1] (2025-02-14).
EXPERIMENTAL SOFTWARE: if you find a bug, please consider opening an issue in
https://github.com/crystal-lang/crystal/issues/new/
In example.cr:3:27
3 | opt_parser = OptionParser.parse do |parser|
^----
Error: BUG: missing downcast_distinct from String to OptionParser (Crystal::NonGenericClassType to Crystal::NonGenericClassType)
In example.cr:4:3
4 | parser.on("-h", "--help", "Show help") do
^-----
Error: BUG: missing downcast_distinct from String to OptionParser (Crystal::NonGenericClassType to Crystal::NonGenericClassType)
Can be reproduced with 1.15.1, but also with master:
$ crystal -v
Crystal 1.16.0-dev [9b7fd8dc1] (2025-02-14)
The compiler was not built in release mode.
LLVM: 19.1.7
Default target: x86_64-pc-linux-gnu
OS: Arch Linux