From: Andreas Rottmann Subject: Fix argument duplication `define-inlinable' in SRFI-9 * modules/srfi/srfi-9.scm (define-inlinable): Don't duplicate argument expressions in the expansion of the macros generated. * test-suite/tests/srfi-9.test (constructor): Adapted. (side-effecting arguments): New test for the argument duplication issue. --- module/srfi/srfi-9.scm | 5 +++-- test-suite/tests/srfi-9.test | 22 +++++++++------------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/module/srfi/srfi-9.scm b/module/srfi/srfi-9.scm index fad570b..34dbb53 100644 --- a/module/srfi/srfi-9.scm +++ b/module/srfi/srfi-9.scm @@ -87,8 +87,9 @@ (define-syntax name (lambda (x) (syntax-case x () - ((_ formals ...) - #'(begin body ...)) + ((_ . arguments) + #'(call-with-values (lambda () (values . arguments)) + (lambda (formals ...) body ...))) (_ (identifier? x) #'proc-name)))))))))) diff --git a/test-suite/tests/srfi-9.test b/test-suite/tests/srfi-9.test index f8006c4..6766482 100644 --- a/test-suite/tests/srfi-9.test +++ b/test-suite/tests/srfi-9.test @@ -38,21 +38,10 @@ (with-test-prefix "constructor" - ;; Constructors are defined using `define-integrable', meaning that direct - ;; calls as in `(make-foo)' lead to a compile-time psyntax error, hence the - ;; distinction below. - - (pass-if-exception "foo 0 args (inline)" exception:syntax-pattern-unmatched - (compile '(make-foo) #:env (current-module))) - (pass-if-exception "foo 2 args (inline)" exception:syntax-pattern-unmatched - (compile '(make-foo 1 2) #:env (current-module))) - (pass-if-exception "foo 0 args" exception:wrong-num-args - (let ((make-foo make-foo)) - (make-foo))) + (make-foo)) (pass-if-exception "foo 2 args" exception:wrong-num-args - (let ((make-foo make-foo)) - (make-foo 1 2)))) + (make-foo 1 2))) (with-test-prefix "predicate" @@ -94,6 +83,13 @@ (pass-if-exception "set-y! on bar" exception:wrong-type-arg (set-y! b 99))) +(with-test-prefix "side-effecting arguments" + + (pass-if "predicate" + (let ((x 0)) + (and (foo? (begin (set! x (+ x 1)) f)) + (= x 1))))) + (with-test-prefix "non-toplevel" (define-record-type :frotz (make-frotz a b) frotz? -- tg: (df12979..) t/srfi-9-fix2 (depends on: stable-2.0)