match a sum through a pointer to it

A pointer was refused, where . reads through one; a match now reads
through the whole chain of them to the sum.
This commit is contained in:
2026-10-19 14:48:43 +03:00
parent 2fa1ed21d7
commit f66eaa7454
2 changed files with 21 additions and 1 deletions

View File

@@ -1018,7 +1018,7 @@
;;; binders, or a variant left out with no `else' are all errors here:
;;; a missing case is the thing this form exists to catch.
(define (walk-match form env)
(let* ((scrutinee (and (pair? (cdr form)) (second form)))
(let* ((scrutinee (and (pair? (cdr form)) (dereferenced (second form) env form)))
;; a comment between arms goes the way the writer already
;; drops one between switch clauses
(arms (remove comment-form? (cddr form)))
@@ -1042,6 +1042,13 @@
,(match-branches name held variants arms))
env)))))
;;; A pointer to a sum is matched as the sum, read through however many
;;; there are, as `.' reads through them: p : (* * shape) -> (* (* p))
(define (dereferenced expr env form)
(if (pointer-target (expression-type expr env))
(dereferenced (copy-form-source! form (list '* expr)) env form)
expr))
(define (match-binders arms)
(append-map (lambda (arm)
(if (eq? (car arm) 'else) '() (delete '_ (second (car arm)))))