diff --git a/semen.scm b/semen.scm index 28aaf74..4dc53b1 100644 --- a/semen.scm +++ b/semen.scm @@ -1579,8 +1579,10 @@ (define (lift-lambda name form) (match form (('lambda arglist ret-type . body) - (process-fn (copy-form-source! form `(fn ,name ,arglist ,ret-type - ,@(defining body))) + (process-fn (copy-form-source! + form + `(fn ,name ,(named-parameters arglist) ,ret-type + ,@(defining body))) (list))) (else (sex-error form "malformed lambda" form)))) @@ -1946,7 +1948,8 @@ ;;; type alone gets a name nothing reads: ((int) (b int)) -> ((ƛu0 int) (b int)) (define (named-parameters arglist) (map (lambda (arg index) - (if (or (named-arg? arg) (comment-form? arg)) + (if (or (named-arg? arg) (comment-form? arg) + (eq? arg '...) (equal? arg '(...))) arg (list (string->symbol (string-append "ƛu" (number->string index))) (unwrap-type arg)))) diff --git a/tests/codegen.scm b/tests/codegen.scm index 9ccb997..5c967ca 100644 --- a/tests/codegen.scm +++ b/tests/codegen.scm @@ -561,6 +561,14 @@ whitespace aside, THEN?" (test-assert "and its code names it, a definition needing one before C23" (emits? (in-fn "(var c (closure ((int) (int)) int) (closure ((int) (b int)) int () (return b)))") "int ƛu0, int b)")) + ;; a definition names every parameter before C23, a lambda's as a + ;; closure's code does + (test-assert "a lambda's unnamed parameter is named in its definition" + (emits? "(fn f () void (var g (fn ((int) (int)) int) (lambda ((int) (b int)) int (return b))))" + "λ0_f (int ƛu0, int b)")) + (test-assert "and a variadic one keeps its ..." + (emits? "(fn f () void (var g (fn ((int) ...) int) (lambda ((n int) ...) int (return n))))" + "λ0_f (int n, ...)")) ;; a lifted function with no body was a declaration of one, and ;; nothing defined it (test-assert "an empty lambda is an empty function"