crystal-lang / crystal

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

Interpreter: bug with regexes #12768

Open hutou opened 2 years ago

hutou commented 2 years ago

In my application, which consists of a dozen files totalling about 5000 lines, I use regular expression tests in various places (about 40). The compilation proceeds normally. When I try to run it under the interpreter (from I3oris], I get the following error message:

BUG: can't find local var $~ (Exception)
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:803:32 in 'visit'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:3170:5 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/enumerable.cr:453:7 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:3170:5 in 'visit'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:3170:5 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/enumerable.cr:453:7 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:199:5 in 'create_compiled_def'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1863:22 in 'visit'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/enumerable.cr:453:7 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/semantic/bindings.cr:16:7 in 'compile_def'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:2064:5 in 'create_compiled_def'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1863:22 in 'visit'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1284:8 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:3170:5 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/enumerable.cr:453:7 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1284:8 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1296:8 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1296:8 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/semantic/bindings.cr:16:7 in 'compile_def'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:2064:5 in 'create_compiled_def'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1863:22 in 'visit'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1284:8 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/enumerable.cr:453:7 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/semantic/bindings.cr:16:7 in 'compile_def'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:2064:5 in 'create_compiled_def'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:1863:22 in 'visit'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/enumerable.cr:453:7 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:3170:5 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/enumerable.cr:453:7 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:3170:5 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/enumerable.cr:453:7 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/semantic/bindings.cr:16:7 in 'visit'
  from /home/hubert/abs/ic/share/crystal-ic/src/enumerable.cr:453:7 in 'accept'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/compiler.cr:3362:11 in 'compile'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/interpreter.cr:223:5 in 'interpret'
  from /home/hubert/abs/ic/share/crystal-ic/src/compiler/crystal/interpreter/repl.cr:106:5 in 'interpret_and_exit_on_error'
  from /home/hubert/abs/ic/share/crystal-ic/src/gc/boehm.cr:129:5 in '__crystal_main'
  from /home/hubert/abs/ic/share/crystal-ic/src/crystal/main.cr:115:5 in 'main'
  from /usr/lib/libc.so.6 in '??'
  from /usr/lib/libc.so.6 in '__libc_start_main'
  from ../sysdeps/x86_64/start.S:117 in '_start'
  from ???

I do not use the $~ syntax in the source code.

devnote-dev commented 1 month ago

I'm not sure if this is the same issue but running /bar/ in the interpreter produces this:

undefined reference to `pcre2_compile_8' (Crystal::Loader::LoadError)
  from D:\a\crystal\crystal\src\compiler\crystal\loader.cr:76 in 'find_symbol'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1885 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1283 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2103 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2103 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2103 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2103 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1497 in 'get_const_index_and_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1469 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:161 in 'compile'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\interpreter.cr:232 in 'interpret'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\repl.cr:25 in 'run'
  from D:\a\crystal\crystal\src\compiler\crystal\command.cr:55 in 'run'
  from D:\a\crystal\crystal\src\compiler\crystal.cr:11 in '__crystal_main'
  from D:\a\crystal\crystal\src\crystal\main.cr:130 in 'main'
  from D:\a\crystal\crystal\src\crystal\system\win32\wmain.cr:37 in 'wmain'
  from D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 in '__scrt_common_main_seh'
  from C:\WINDOWS\System32\KERNEL32.DLL +75133 in 'BaseThreadInitThunk'
  from C:\WINDOWS\SYSTEM32\ntdll.dll +372520 in 'RtlUserThreadStart'

Running /bar/ again produces this:

Unhandled case: enum value outside of defined enum members (Exception)
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\interpreter.cr:354 in 'interpret'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\interpreter.cr:252 in 'interpret'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\repl.cr:25 in 'run'
  from D:\a\crystal\crystal\src\compiler\crystal\command.cr:55 in 'run'
  from D:\a\crystal\crystal\src\compiler\crystal.cr:11 in '__crystal_main'
  from D:\a\crystal\crystal\src\crystal\main.cr:130 in 'main'
  from D:\a\crystal\crystal\src\crystal\system\win32\wmain.cr:37 in 'wmain'
  from D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 in '__scrt_common_main_seh'
  from C:\WINDOWS\System32\KERNEL32.DLL +75133 in 'BaseThreadInitThunk'
  from C:\WINDOWS\SYSTEM32\ntdll.dll +372520 in 'RtlUserThreadStart'

Similarly, "foo" =~ /bar/ produces this:

undefined reference to `pcre2_match_data_create_from_pattern_8' (Crystal::Loader::LoadError)
  from D:\a\crystal\crystal\src\compiler\crystal\loader.cr:76 in 'find_symbol'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1885 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2028 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2103 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2103 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1283 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2103 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1305 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2103 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1293 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2103 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\syntax\visitor.cr:27 in 'accept'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:244 in 'compile_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:2103 in 'create_compiled_def'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:1898 in 'visit'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\compiler.cr:161 in 'compile'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\interpreter.cr:232 in 'interpret'
  from D:\a\crystal\crystal\src\compiler\crystal\interpreter\repl.cr:25 in 'run'
  from D:\a\crystal\crystal\src\compiler\crystal\command.cr:55 in 'run'
  from D:\a\crystal\crystal\src\compiler\crystal.cr:11 in '__crystal_main'
  from D:\a\crystal\crystal\src\crystal\main.cr:130 in 'main'
  from D:\a\crystal\crystal\src\crystal\system\win32\wmain.cr:37 in 'wmain'
  from D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288 in '__scrt_common_main_seh'
  from C:\WINDOWS\System32\KERNEL32.DLL +75133 in 'BaseThreadInitThunk'
  from C:\WINDOWS\SYSTEM32\ntdll.dll +372520 in 'RtlUserThreadStart'

However, this behaviour is inconsistent. Sometimes the interpreter will exit without warning, other times it repeats the enum exception. Sometimes it crashes altogether:

image