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 2b88286411
commit 245e144ccb
5 changed files with 60 additions and 4 deletions

View File

@@ -537,6 +537,17 @@ ahead of its pub forms."
(interface-reports? "(pub var n _ 42)" "write it out"))
(test-assert "all of it"
(interface-reports? "(pub var p (* _) 0)" "write it out"))
;; a spec is seen by importers as a type is: pub, or not at all
(test-assert "a pub realization of a private spec is refused"
(interface-reports? (string-append "(spec (shown T) (fn show ((self (* const T))) int))"
"(pub record m ((c int)))"
"(pub realize (shown m) (fn show ((self (* const m))) int (return 1)))")
"importers cannot see this spec; make it pub"))
(test "and of a pub one is not"
'()
(interface-of (string-append "(pub spec (shown T) (fn show ((self (* const T))) int))"
"(pub record m ((c int)))"
"(pub realize (shown m) (fn show ((self (* const m))) int (return 1)))")))
(test "a private one is solved where it is"
'()
(interface-of "(var n _ 42)"))

View File

@@ -50,6 +50,14 @@
(define sexc (or (get-environment-variable "SEXC") "../../sexc"))
;;; What PROGRAM run with ARGS writes to stderr when it fails, or #f
(define (error-of program . args)
(let* ((proc (process* program args))
(err (begin (read-string #f (process-output-port proc))
(read-string #f (process-error-port proc)))))
(process-wait proc)
(and (not (zero? (process-exit-status proc))) (string? err) err)))
;;; The lines PROGRAM prints when run with ARGS, or #f when it fails
(define (output-of program . args)
(let* ((proc (process program args))
@@ -95,6 +103,12 @@
'("cycle 1 2")
(output-of "./cycle-app"))
;;; ...while a realization of a spec importers cannot see is refused by
;;; the module that writes it, not by an importer naming it first
(test-assert "a pub realization of a spec imported without pub is refused"
(let ((err (error-of sexc "specs/money.sex" "-C" "-o" "-")))
(and err (irregex-search "money.sex:8: importers cannot see this spec" err) #t)))
(test "the app runs through both"
'("hello, world"
"hello, sex"

View File

@@ -0,0 +1,9 @@
;;; Imports shown without pub, so its importers cannot see the spec
;;; this realizes: refused here, rather than in whichever importer
;;; names money before shown
(import shown)
(pub record money ((cents int)))
(pub realize (shown money)
(fn show ((self (* const money))) int (return (. self cents))))

View File

@@ -0,0 +1,2 @@
(pub spec (shown T)
(fn show ((self (* const T))) int))