diff --git a/semen.scm b/semen.scm index e758705..c4cf2e6 100644 --- a/semen.scm +++ b/semen.scm @@ -283,6 +283,14 @@ ;; be answered from the scope it was written in (expanded (append (macro-expand (take sex-fn boundary)) (drop sex-fn boundary)))) + ;; a `_' is solved from what a variable is set to, and a signature + ;; has nothing it is set to + (when (mentions? (cons (sex-fn-return-type expanded) + (arglist-types (sex-fn-arglist expanded))) + '_) + (sex-error sex-fn-raw + "a function's types are written out; `_' is a variable's" + (sex-fn-name expanded))) (add-name-type! (sex-fn-name expanded) (fn-type-of expanded)) (let* ((env (make-fn-env expanded)) ;; the parameters are the body's outermost scope diff --git a/tests/codegen.scm b/tests/codegen.scm index 61cc84d..90cd5e5 100644 --- a/tests/codegen.scm +++ b/tests/codegen.scm @@ -753,6 +753,17 @@ whitespace aside, THEN?" (test-assert "and a field" (emits? "(struct h ((xs [int 4]))) (fn f ((v (struct h))) void (var p _ (. v xs)))" "int * p = v.xs")) + ;; nothing solves a `_' in a signature: it reached C as one + (test-assert "a parameter's type is written out" + (reports? "(fn id ((x _)) int (return x))" "a function's types are written out")) + (test-assert "and so is the return type" + (reports? "(fn id ((x int)) _ (return x))" "a function's types are written out")) + (test-assert "a lambda's as well" + (reports? (in-fn "(var l (fn ((int)) int) (lambda ((x _)) int (return x)))") + "a function's types are written out")) + (test-assert "and a closure's" + (reports? (in-fn "(var c (closure ((int)) int) (closure ((x int)) _ () (return x)))") + "a function's types are written out")) (test-assert "while a function is the pointer it already is" (emits? "(fn g ((n int)) int (return n)) (fn f () void (var p _ g))" "int (*p)(int) = g"))