From 4ac386f373a462b029f23989e33c505a9f14bcc3 Mon Sep 17 00:00:00 2001 From: alex-eg Date: Thu, 15 Oct 2026 14:44:34 +0300 Subject: [PATCH] hold a function type's parameters by value on the interface A record a pub function type took or returned by value was declared only, so an importer could neither define a callback for it nor call one. --- sex-modules.scm | 7 +++++-- tests/encapsulation.scm | 9 +++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/sex-modules.scm b/sex-modules.scm index 199a044..7a68e91 100644 --- a/sex-modules.scm +++ b/sex-modules.scm @@ -202,7 +202,10 @@ ;;; ;;; (* const cell) -> ((const . #t) (cell . #t)) ;;; [cell 4] -> ((cell . #f)) -;;; (fn ((cell)) int) -> ((cell . #t) (int . #t)) ; declaring is enough +;;; (fn ((cell)) int) -> ((cell . #f) (int . #f)) +;;; +;;; A function type takes and returns by value whatever it is held +;;; through: C wants the body to define or call one of its functions. (define (type-uses type behind?) (cond ((symbol? type) (list (cons type behind?))) @@ -215,7 +218,7 @@ (if (array-bound? type) (bound-uses (last type)) (list))))) ((fn closure) (if (and (pair? (cdr type)) (list? (second type))) - (append-map (lambda (t) (type-uses t #t)) + (append-map (lambda (t) (type-uses t #f)) (signature-types (second type) (last type))) (list))) ((struct union enum) diff --git a/tests/encapsulation.scm b/tests/encapsulation.scm index a83e996..b579c94 100644 --- a/tests/encapsulation.scm +++ b/tests/encapsulation.scm @@ -527,6 +527,15 @@ ahead of its pub forms." "held by value")) (test-assert "returned" (interface-reports? "(record cell ((v int))) (pub fn f () cell)" "held by value")) + (test-assert "or taken by a function a pub one takes" + (interface-reports? "(record cell ((v int))) (pub fn take ((cb (fn ((c cell)) void))) void)" + "held by value")) + (test-assert "or returned by one" + (interface-reports? "(record cell ((v int))) (pub fn take ((cb (fn () cell))) void)" + "held by value")) + (test "but a pointer there is still a pointer" + '((record cell)) + (interface-of "(record cell ((v int))) (pub fn take ((cb (fn ((c (* cell))) void))) void)")) (test-assert "or taken by a pub method" (interface-reports? "(record cell ((v int))) (ops cell (pub fn get ((self cell)) int))" "held by value"))