1
0
forked from alex-eg/sex

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

@@ -504,6 +504,19 @@ ahead of its pub forms."
(emits? (sum-src "(var c (closure () int) (closure () int ((t s))"
" (match t ((circle (r)) (return 1)) (else (return 0)))))")
"t.tag == shapeǂcircle"))
;; a pointer to one was refused, where `.' reads through one
(test-assert "a pointer to a sum is matched as the sum"
(emits? (sum-src "(var p (* shape) (& s))"
"(match p ((circle (r)) (= out r)) (else (= out 0.0)))")
"(*p).tag == shapeǂcircle"))
(test-assert "binding through it"
(emits? (sum-src "(var p (* shape) (& s))"
"(match p ((circle (r)) (= out r)) (else (= out 0.0)))")
"float r = (*p).u.circle.r"))
(test-assert "and through a chain of them"
(emits? (sum-src "(var p (* shape) (& s)) (var pp (* * shape) (& p))"
"(match pp ((circle (r)) (= out r)) (else (= out 0.0)))")
"(*(*pp)).tag == shapeǂcircle"))
(test-assert "and a scrutinee that is not a sum"
(reports? "(fn f () void (var n int 1) (match n ((a ()) (= n 2))))"
"match wants a sum")))