diff --git a/sex-modules.scm b/sex-modules.scm index a91da8f5..466e8c53 100644 --- a/sex-modules.scm +++ b/sex-modules.scm @@ -138,6 +138,7 @@ (reverse (fold (lambda (form acc) + (check-written-out form) (fold (lambda (use acc) (check-type-use form use visible hidden acc)) acc (append-map (lambda (type) (type-uses type #f)) @@ -145,6 +146,20 @@ (list) forms)))) +;;; Importers declare a pub var from its type, not its initializer, so +;;; there is nothing on their side to solve a `_' with +(define (check-written-out form) + (match form + (('pub 'var . _) + (match (strip-header-comments form 4) + (('pub 'var name type . _) + (when (let wildcard? ((t type)) + (or (eq? t '_) (and (pair? t) (any wildcard? t)))) + (sex-error form "a pub var's type is what importers declare it with; write it out" + name))) + (_ #f))) + (_ #f))) + ;;; USE is (name . behind-a-pointer?) (define (check-type-use form use visible hidden acc) (let* ((name (car use)) diff --git a/tests/encapsulation.scm b/tests/encapsulation.scm index bff967c0..b666c2a4 100644 --- a/tests/encapsulation.scm +++ b/tests/encapsulation.scm @@ -530,6 +530,15 @@ ahead of its pub forms." (test "nor a private fn's" '() (interface-of "(record cell ((v int))) (fn f ((c cell)) void)")) + ;; importers are given the declaration, not the initializer, so `_' + ;; reached them unsolved: `extern _ n' + (test-assert "a pub var's type is written out" + (interface-reports? "(pub var n _ 42)" "write it out")) + (test-assert "all of it" + (interface-reports? "(pub var p (* _) 0)" "write it out")) + (test "a private one is solved where it is" + '() + (interface-of "(var n _ 42)")) (test-assert "held by value it is an error" (interface-reports? "(record cell ((v int))) (pub record shape ((c cell)))" "held by value"))