Skip to content

emit-c: a fn value whose type returns an array has no C lowering (refused since #1775) #1817

Closed

Description

@ehartford

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.

Activity

  1. added a commit that references this issue on Oct 3, 2026
  2. ehartford commented on Oct 3, 2026

    @ehartford
    ContributorAuthor

    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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions