Open
Description
Bug Report
Any code explicitly returning a lib struct or a tuple inside a fun
results in a codegen error.
Here's an example (also works with empty prelude):
lib LibFoo
struct Bar
value : Int32
end
end
fun foo : LibFoo::Bar
return LibFoo::Bar.new
end
This results in the following compilation error:
Module validation failed: Function return type does not match operand type of return inst!
ret %"struct.LibFoo::Bar" %2, !dbg !668
{ i64 } (Exception)
from /crystal/src/string.cr:5488:31 in 'codegen'
from /crystal/src/compiler/crystal/compiler.cr:195:16 in 'compile:combine_rpath'
from /crystal/src/compiler/crystal/compiler.cr:188:56 in 'compile:combine_rpath'
from /crystal/src/compiler/crystal/command/eval.cr:30:5 in 'eval'
from /crystal/src/compiler/crystal/command.cr:125:12 in 'run'
from /crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
from /crystal/src/crystal/main.cr:129:5 in 'main'
from src/env/__libc_start_main.c:95:2 in 'libc_start_main_stage2'
Another example:
fun foo : {Int32}
return {0}
end
..which results in this error:
Module validation failed: Function return type does not match operand type of return inst!
ret %"Tuple(Int32)" %2, !dbg !668
{ i64 } (Exception)
from /crystal/src/string.cr:5488:31 in 'codegen'
from /crystal/src/compiler/crystal/compiler.cr:195:16 in 'compile:combine_rpath'
from /crystal/src/compiler/crystal/compiler.cr:188:56 in 'compile:combine_rpath'
from /crystal/src/compiler/crystal/command/eval.cr:30:5 in 'eval'
from /crystal/src/compiler/crystal/command.cr:125:12 in 'run'
from /crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
from /crystal/src/crystal/main.cr:129:5 in 'main'
from src/env/__libc_start_main.c:95:2 in 'libc_start_main_stage2'
System information
$ crystal -v
Crystal 1.11.2 [fda656c71] (2024-01-18)
LLVM: 15.0.7
Default target: x86_64-unknown-linux-gnu
Activity