refuse a pub realization of a spec importers cannot see

It failed in whichever importer named the module before the spec's,
pointing at the module, where a hidden type is refused in the module
already: so is this, the remedy the same.
This commit is contained in:
2026-10-19 14:18:56 +03:00
parent 9af5360131
commit 2bc07a5a5f
5 changed files with 60 additions and 4 deletions

View File

@@ -182,6 +182,7 @@
(fold
(lambda (form acc)
(check-written-out form)
(check-realized-spec form visible hidden)
(fold (lambda (use acc) (check-type-use form use visible hidden acc))
acc
(append-map (lambda (type) (type-uses type #f))
@@ -203,6 +204,22 @@
(_ #f)))
(_ #f)))
;;; A pub realization goes to importers, who look its spec up; one they
;;; cannot see failed there, in whichever named this module before the
;;; spec's, and said nothing of where it was written
(define (check-realized-spec form visible hidden)
(match form
(('pub 'realize ((? symbol? spec) _) . _)
(let ((kept (assq spec hidden)))
(when (and kept (not (assq spec visible)))
(sex-error form
(string-append "importers cannot see this spec; "
(if (fourth kept)
"import its module with pub"
"make it pub"))
spec))))
(_ #f)))
;;; USE is (name . behind-a-pointer?)
(define (check-type-use form use visible hidden acc)
(let* ((name (car use))
@@ -304,25 +321,28 @@
((pair? bound) (append-map bound-uses (cdr bound)))
(else (list))))
;;; The types and constants FORMS declare, as (name kind body?):
;;; The types, constants and specs FORMS declare, as (name kind body?):
;;;
;;; (pub record tally) -> (tally record #f)
;;; (sum colour ((none ()))) -> (colour sum #t)
;;; (define (sq x) (* x x)) -> (sq define #t)
;;; (spec (shown T) ...) -> (shown spec #t)
(define (declared-types forms)
(filter-map
(lambda (form)
(and (pair? form)
(let* ((core (strip-pub form))
(name (and (pair? core) (pair? (cdr core))
(if (and (eq? (car core) 'define) (pair? (second core)))
(if (and (memq (car core) '(define spec))
(pair? (second core)))
(car (second core))
(second core)))))
(and (memq (car core) '(record struct union enum sum typedef define))
(and (memq (car core)
'(record struct union enum sum typedef define spec))
(symbol? name)
(list name
(car core)
(or (memq (car core) '(typedef define))
(or (memq (car core) '(typedef define spec))
(any list? (remove comment-form? (cddr core)))))))))
forms))