From a0b323980fdec01cbbdb8e0957c4f3fb56c0357f Mon Sep 17 00:00:00 2001 From: alex-eg Date: Mon, 19 Oct 2026 15:32:47 +0300 Subject: [PATCH] refuse a match in a case label case and case/fallthrough walked their label as a statement, so a match there was taken and wrote `case switch:'. --- semen.scm | 7 +++++-- tests/encapsulation.scm | 7 +++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/semen.scm b/semen.scm index c9b33c7f..888445f2 100644 --- a/semen.scm +++ b/semen.scm @@ -591,7 +591,10 @@ ((for while if switch) (with-scope env (lambda () (walk-control form env)))) - ((case case/fallthrough default) + ((case case/fallthrough) + (walk-control form env)) + + ((default) (parameterize ((operand-position? #f)) (walk-parts form env))) @@ -899,7 +902,7 @@ ;;; Whether the Ith of a control form's SLOTS is read as a value: an ;;; `if''s tests but not its trailing else, a `for''s header, the -;;; scrutinee of a `while' or a `switch' +;;; scrutinee of a `while' or a `switch', a `case''s label (define (test-slot? head i slots) (case head ((if) (and (even? i) (< (+ i 1) slots))) diff --git a/tests/encapsulation.scm b/tests/encapsulation.scm index 3d5b5772..8df2b098 100644 --- a/tests/encapsulation.scm +++ b/tests/encapsulation.scm @@ -452,6 +452,13 @@ (reports? (sum-src "(for (var i int 0) (match s ((circle (r)) 1) (else 0)) (++ i)" " (= out 1.0))") "match is a statement")) + (test-assert "nor as a case label" + (reports? (sum-src "(switch 1 (case (match s ((circle (r)) 1) (else 0)) (= out 1.0)))") + "match is a statement")) + (test-assert "nor as a case/fallthrough's" + (reports? (sum-src "(switch 1 (case/fallthrough (match s ((circle (r)) 1) (else 0))" + " (= out 1.0)))") + "match is a statement")) (test-assert "but an if's branches are statements, the else among them" (emits? (sum-src "(if (== out 0.0) (match s ((circle (r)) (= out r)) (else (= out 1.0)))" " (match s ((circle (r)) (= out 2.0)) (else (= out 3.0))))")