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
{{ message }}
Repository navigation
emit-c: a fn value whose type returns an array has no C lowering (refused since #1775) #1817
Follow-up of #1775. A named function returning [N]T now takes the destination as a leading void* __with_ret out-pointer (C returns no arrays). A fn VALUE of such a type — the fat {fn_ptr, ctx} typedef of a fn(...) -> [N]T, an extern "C" fn pointer typedef, or a fat thunk for a named function materialized as a value — would need the same out-pointer threaded through the typedef, the thunk and every indirect call site. CCodegen refuses it loudly instead (emit-c: a fn value whose type returns an array has no C lowering ..., emit_fn_type_defs and emit_fat_thunk_defs), rather than declaring the old pointer return.
Repro (expected to be refused by --emit-c today, printing 9 under the LLVM backend):
fn arr() -> [u16; 2]: [7u16, 9u16]
fn main:
let f = arr
let a = f()
print(f"{a[1]}")
Expected: the fn-value path uses the same out-pointer convention (one decision — the FnAbi rule — read by typedef, thunk and call site), and the refusal goes.
Fixed on main by 7b56d3f (stack #1979, battery green on 029574d). emit-c lowers fn values, thunks and closures returning an array with the destination pointer after the context argument; test/emit_c/fn_value_array_return.w; an extern "C" fn returning an array stays refused (see #1975).
Activity
c_import/migrate/emit-c: no `-> Unit` on void C fns (#1838); header f…
ehartford commentedon Oct 3, 2026
Fixed on main by 7b56d3f (stack #1979, battery green on 029574d). emit-c lowers fn values, thunks and closures returning an array with the destination pointer after the context argument; test/emit_c/fn_value_array_return.w; an extern "C" fn returning an array stays refused (see #1975).