crystal-lang / crystal

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

Interpreter Error: can't cast Pointer(Void) to (Pointer(Void) | String) #14628

Open BlobCodes opened 1 month ago

BlobCodes commented 1 month ago

Bug Report

Unions with pointers don't seem to work correctly in some cases in the interpreter:

puts "0", Pointer(Void).null
# => can't cast Pointer(Void) to (Pointer(Void) | String)

puts "0", Pointer(Void).null
# Unhandled case: enum value outside of defined enum members (Exception)
#   from src/compiler/crystal/interpreter/interpreter.cr:354:7 in 'interpret'
#   from src/compiler/crystal/interpreter/interpreter.cr:252:13 in 'interpret'
#   from src/compiler/crystal/interpreter/repl.cr:92:5 in 'interpret'
#   from src/compiler/crystal/interpreter/repl.cr:53:13 in 'parse_and_interpret'
#   from src/compiler/crystal/interpreter/repl.cr:25:18 in 'run'
#   from src/compiler/crystal/command/repl.cr:39:7 in 'repl'
#   from src/compiler/crystal/command.cr:104:7 in 'run'
#   from src/compiler/crystal/command.cr:55:5 in 'run'
#   from src/compiler/crystal/command.cr:54:3 in 'run'
#   from src/compiler/crystal.cr:11:1 in '__crystal_main'
#   from src/crystal/main.cr:117:5 in 'main_user_code'
#   from src/crystal/main.cr:103:7 in 'main'
#   from src/crystal/main.cr:129:3 in 'main'
#   from /lib64/libc.so.6 in '??'
#   from /lib64/libc.so.6 in '__libc_start_main'
#   from /var/home/blob/Projekte/crystal/.build/crystal in '_start'
#   from ???

$ bin/crystal -v
Using compiled compiler at .build/crystal
Crystal 1.13.0-dev [5f9bb9e8e] (2024-05-24)

The compiler was not built in release mode.

LLVM: 18.1.1
Default target: x86_64-redhat-linux-gnu