crystal-lang / crystal

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

Cannot return `Proc`s from top-level funs #14691

Open HertzDevil opened 3 weeks ago

HertzDevil commented 3 weeks ago

The following:

fun foo : -> Int32
  -> { 1 }
end

produces a codegen error:

Module validation failed: Function return type does not match operand type of return inst!
  ret %"->" %3, !dbg !664
 ptr

This happens even when using a ProcPointer:

fun foo : LibC::Char* -> LibC::SizeT
  ->LibC.strlen
end

It looks like the fun is trying to return a Crystal Proc that contains an additional closure data pointer; instead, it should reject any closures and return just the function pointer using ~check_proc_is_not_closure, similar to when a Proc is passed as a lib call argument.