crystal-lang / crystal

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

Interpreter: "BUG: missing local var migration from Nil to (String | Nil) (Exception)" #14770

Open philipp-classen opened 3 months ago

philipp-classen commented 3 months ago

The following REPL session triggers an unhandled case in the interpreter: https://github.com/crystal-lang/crystal/blob/5b500882bb51cff0f38a51735bf008923cde2219/src/compiler/crystal/interpreter/interpreter.cr#L503

Using compiled compiler at github/crystal/.build/crystal
Crystal interpreter 1.13.0-dev [e279b3c7f] (2024-07-01).
EXPERIMENTAL SOFTWARE: if you find a bug, please consider opening an issue in
https://github.com/crystal-lang/crystal/issues/new/

icr:1> x = ""
 => ""
icr:2> y : String? = nil
 => nil
icr:3> y = x

BUG: missing local var migration from Nil to (String | Nil) (Exception)
  from github/crystal/src/compiler/crystal/interpreter/interpreter.cr:503:11 in 'migrate_local_vars'
  from github/crystal/src/compiler/crystal/interpreter/interpreter.cr:182:7 in 'interpret'
  from github/crystal/src/compiler/crystal/interpreter/repl.cr:92:5 in 'interpret'
  from github/crystal/src/compiler/crystal/interpreter/repl.cr:53:13 in 'parse_and_interpret'
  from github/crystal/src/compiler/crystal/interpreter/repl.cr:25:18 in 'run'
  from github/crystal/src/compiler/crystal/command/repl.cr:39:7 in 'repl'
  from github/crystal/src/compiler/crystal/command.cr:104:7 in 'run'
  from github/crystal/src/compiler/crystal/command.cr:55:5 in 'run'
  from github/crystal/src/compiler/crystal/command.cr:54:3 in 'run'
  from github/crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
  from github/crystal/src/crystal/main.cr:118:5 in 'main_user_code'
  from github/crystal/src/crystal/main.cr:104:7 in 'main'
  from github/crystal/src/crystal/main.cr:130:3 in 'main'
  from /usr/lib/libc.so.6 in '??'
  from /usr/lib/libc.so.6 in '__libc_start_main'
  from /home/phil/github/crystal/.build/crystal in '_start'
  from ???

Can be reproduced on master (tested with e279b3c7f90a43ff654694d9f7726a244aeda988)

OS: Arch Linux

$ crystal --version
Crystal 1.12.2 (2024-06-01)

LLVM: 17.0.6
Default target: x86_64-pc-linux-gnu