refuse _ in a pub var's type

Importers declare a pub var from its type alone, with nothing to solve
a wildcard against, so (pub var n _ 42) reached them as extern _ n.
This commit is contained in:
2026-10-16 17:04:20 +03:00
parent f304d92b8d
commit 54a79ee75e
2 changed files with 24 additions and 0 deletions

View File

@@ -141,6 +141,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))
@@ -148,6 +149,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))

View File

@@ -531,6 +531,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"))