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:
@@ -505,6 +505,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")))
|
||||
|
||||
Reference in New Issue
Block a user