Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BUG: missing downcast_distinct from String to OptionParser (Crystal::NonGenericClassType to Crystal::NonGenericClassType) #15489

Open
philipp-classen opened this issue Feb 18, 2025 · 1 comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter

Comments

@philipp-classen
Copy link
Contributor

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

@philipp-classen philipp-classen added the kind:bug A bug in the code. Does not apply to documentation, specs, etc. label Feb 18, 2025
@straight-shoota
Copy link
Member

Similar previous downcast bugs in the interpreter: #12283, #12532, #12342
I presume the fix could be similar to one of these.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:interpreter
Projects
None yet
Development

No branches or pull requests

3 participants