aboutsummaryrefslogtreecommitdiff
path: root/test/values.tm
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-11-26 21:12:11 -0500
committerBruce Hill <bruce@bruce-hill.com>2025-11-26 21:12:11 -0500
commit3ad07260f369dc285e5ae856b78a58c3b13ee622 (patch)
tree7ba216c5482147ac53edaca62389029c34b4a66c /test/values.tm
parenta21f9ddfd05c643049c22bb52ab3a60f41933492 (diff)
Close loophole in `when` statements that allowed mutating inner field
members
Diffstat (limited to 'test/values.tm')
-rw-r--r--test/values.tm8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/values.tm b/test/values.tm
index 86f34a89..9f86c012 100644
--- a/test/values.tm
+++ b/test/values.tm
@@ -3,6 +3,8 @@ struct Inner(xs:[Int32])
struct Outer(inner:Inner)
+enum HoldsList(HasList(xs:[Int32]))
+
func sneaky(outer:Outer)
(&outer.inner.xs)[1] = 99
@@ -45,3 +47,9 @@ func main()
assert foo.inner.xs == [99, 20, 30]
assert copy.inner.xs == [10, 20, 30]
+ do
+ x := HoldsList.HasList([10, 20, 30])
+ when x is HasList(list)
+ (&list)[1] = 99
+
+ assert x == HoldsList.HasList([10, 20, 30])