From 3476d99690805b3ebe69219b326e5e1b64ebd0a4 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sat, 3 Oct 2026 14:03:48 -0700 Subject: Chapter 17b: Syntax Sugar --- src/test/java/com/seaofnodes/simple/MutabilityTest.java | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/test/java/com/seaofnodes/simple/MutabilityTest.java') diff --git a/src/test/java/com/seaofnodes/simple/MutabilityTest.java b/src/test/java/com/seaofnodes/simple/MutabilityTest.java index 3442c54a..8f99a059 100644 --- a/src/test/java/com/seaofnodes/simple/MutabilityTest.java +++ b/src/test/java/com/seaofnodes/simple/MutabilityTest.java @@ -37,6 +37,12 @@ public class MutabilityTest { bad("struct P { !P? next; int x; }; P p=new P{next=new P;}; p.next.x=7; return 0;"); } + @Test public void testInferencePreservesAccess() { + ok("struct P { int x; }; val p=new P; p.x=7; return p.x;", "7"); + bad("struct P { int x; }; val p=new P; p=new P; return 0;"); + bad("struct P { int x; }; P p=new P; var q=p; q.x=7; return 0;"); + } + @Test public void testConstructorScope() { ok("struct P { int ~x; }; P p=new P{if(arg) x=3; else x=7;}; return p.x;", "7"); bad("int ~outer=1; struct P { int x; }; P p=new P{outer=7;}; return outer;"); -- cgit v1.2.3