From 69e4a21f71aca4954469063387063434af35e679 Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Sun, 25 Oct 2026 10:24:58 -0700 Subject: Backport a few missing guard checks --- .../java/com/seaofnodes/simple/ConstructionTest.java | 17 +++++++++++++++++ .../java/com/seaofnodes/simple/IncompleteTypesTest.java | 13 +++++++++++++ 2 files changed, 30 insertions(+) (limited to 'chapter27/src/test/java/com/seaofnodes') diff --git a/chapter27/src/test/java/com/seaofnodes/simple/ConstructionTest.java b/chapter27/src/test/java/com/seaofnodes/simple/ConstructionTest.java index dd20b746..a3317d09 100644 --- a/chapter27/src/test/java/com/seaofnodes/simple/ConstructionTest.java +++ b/chapter27/src/test/java/com/seaofnodes/simple/ConstructionTest.java @@ -7,6 +7,23 @@ import org.junit.Test; import static org.junit.Assert.*; public class ConstructionTest { + @Test public void testConditionalConstructorLoop() { + String[] bodies = { + "while(n--) if(n) x=1;", + "for(int i=0;i return new C { while(n--) if(n) x=1; }; }; + return f(arg).x; + """; + for( long seed : new long[]{123,456,789} ) { + var code = new CodeGen(src,TypeInteger.BOT,seed,true).driver(CodeGen.Phase.TypeCheck); + for( int arg=0; arg<6; arg++ ) + assertEquals("seed="+seed+" arg="+arg,arg<2 ? "0" : "1",Eval2.eval(code,arg)); + } + } + @Test public void testForwardFieldAndNumericMode() { // At the addition, neither the field's type nor its offset is known. String src = """ -- cgit v1.2.3