Closures written in a few ways reach C unchecked #70

Open
opened 2026-10-19 14:09:44 +02:00 by alex-eg · 0 comments
Owner

Three ways a closure can be written that sexc lets through to C, which then refuses it:

  • A bare function converts to a closure where one is expected in a var initializer, an argument and a return, but not in an assignment or a brace initializer, which reach C as they are:

    (var c (closure ((int)) int) inc)    ->   c = ƛint_int_fromfn(inc);
    (= c inc)                            ->   c = inc;    /* error in C */
    [(closure ((int)) int) 1] #(inc)     ->   {inc}       /* error in C */
    

    Function-values.org says the conversion fires nowhere else, by design; but a sum constructor does convert its arguments, so the rule is uneven.

  • A fn type written unwrapped in a closure's argument list is read as a list of words:

    (closure ((fn ((int)) int) (int)) int)
    ->   int (*code)(void *, int int, int);    /* error in C */
    

    Wrapped, (((fn ((int)) int)) (int)), it works, as a typedef does. That is the convention for every argument, but the mistake is reported by C, about the generated struct.

  • (closure () int) written where a closure value belongs, its captures list forgotten, is taken for a type:

    (var c (closure () int) (closure () int))
    ->   struct ƛvoid_int c = struct ƛvoid_int;    /* error in C */
    

Found with sexc 35604ad, probing corner cases the test suite does not cover; the rest of what that turned up is fixed on more-tests-and-corner-cases.

Three ways a closure can be written that sexc lets through to C, which then refuses it: - A bare function converts to a closure where one is expected in a var initializer, an argument and a return, but not in an assignment or a brace initializer, which reach C as they are: (var c (closure ((int)) int) inc) -> c = ƛint_int_fromfn(inc); (= c inc) -> c = inc; /* error in C */ [(closure ((int)) int) 1] #(inc) -> {inc} /* error in C */ `Function-values.org` says the conversion fires nowhere else, by design; but a sum constructor does convert its arguments, so the rule is uneven. - A `fn` type written unwrapped in a closure's argument list is read as a list of words: (closure ((fn ((int)) int) (int)) int) -> int (*code)(void *, int int, int); /* error in C */ Wrapped, `(((fn ((int)) int)) (int))`, it works, as a typedef does. That is the convention for every argument, but the mistake is reported by C, about the generated struct. - `(closure () int)` written where a closure value belongs, its captures list forgotten, is taken for a type: (var c (closure () int) (closure () int)) -> struct ƛvoid_int c = struct ƛvoid_int; /* error in C */ -------- Found with sexc 35604ad, probing corner cases the test suite does not cover; the rest of what that turned up is fixed on `more-tests-and-corner-cases`.
alex-eg added the bug label 2026-10-19 14:09:44 +02:00
Sign in to join this conversation.