You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Constants defined in an interpreter session, like in compiled code, are not type-checked until the constant is read. If a compilation error occurs during initialization, subsequent reads of the same constant produce an internal error:
icr:1:0> A = 1.foo
=> nil
icr:2:0> A
error in line 1
Error: undefined method 'foo' for Int32
icr:3:0> A
Nil assertion failed (NilAssertionError)
from src/nil.cr:108:5 in 'not_nil!'
from src/compiler/crystal/interpreter/compiler.cr:1453:16 in 'get_const_index_and_compiled_def'
from src/compiler/crystal/interpreter/compiler.cr:2604:27 in 'initialize_const_if_needed'
from src/compiler/crystal/interpreter/compiler.cr:1435:17 in 'visit'
from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
from src/compiler/crystal/interpreter/compiler.cr:157:5 in 'compile'
from src/compiler/crystal/interpreter/interpreter.cr:215:5 in 'interpret'
from src/compiler/crystal/interpreter/repl.cr:100:5 in 'interpret'
from src/compiler/crystal/interpreter/repl.cr:40:17 in 'run'
from src/compiler/crystal/command/repl.cr:37:7 in 'repl'
from src/compiler/crystal/command.cr:100:7 in 'run'
from src/compiler/crystal/command.cr:51:5 in 'run'
from src/compiler/crystal/command.cr:50:3 in 'run'
from src/compiler/crystal.cr:11:1 in '__crystal_main'
from src/crystal/main.cr:115:5 in 'main_user_code'
from src/crystal/main.cr:101:7 in 'main'
from src/crystal/main.cr:127:3 in 'main'
from /lib/x86_64-linux-gnu/libc.so.6 in '??'
from /lib/x86_64-linux-gnu/libc.so.6 in '__libc_start_main'
from /home/quinton/crystal/crystal/.build/crystal in '_start'
from ???
The delayed evaluation matches the behavior of compiled code, but it does look a little strange in a REPL:
icr:1:0> A = B # okay
=> nil
icr:2:0> B = 1
=> nil
icr:3:0> A
=> 1
The interpreter doesn't check the same initializer again after the first time it is evaluated:
icr:1:0> A = B
=> nil
icr:2:0> A
error in line 1
Error: undefined constant B
Did you mean 'A'?
icr:3:0> B = 1
=> nil
icr:4:0> A
Nil assertion failed (NilAssertionError)
The text was updated successfully, but these errors were encountered:
Constants defined in an interpreter session, like in compiled code, are not type-checked until the constant is read. If a compilation error occurs during initialization, subsequent reads of the same constant produce an internal error:
The delayed evaluation matches the behavior of compiled code, but it does look a little strange in a REPL:
The interpreter doesn't check the same initializer again after the first time it is evaluated:
The text was updated successfully, but these errors were encountered: