diff options
Diffstat (limited to 'chapter24/src/test/java/com')
| -rw-r--r-- | chapter24/src/test/java/com/seaofnodes/simple/Chapter10Test.java | 6 | ||||
| -rw-r--r-- | chapter24/src/test/java/com/seaofnodes/simple/Chapter16Test.java | 13 |
2 files changed, 10 insertions, 9 deletions
diff --git a/chapter24/src/test/java/com/seaofnodes/simple/Chapter10Test.java b/chapter24/src/test/java/com/seaofnodes/simple/Chapter10Test.java index d7a74f18..3c5a2913 100644 --- a/chapter24/src/test/java/com/seaofnodes/simple/Chapter10Test.java +++ b/chapter24/src/test/java/com/seaofnodes/simple/Chapter10Test.java @@ -63,6 +63,7 @@ public class Chapter10Test { public void testNullGuardErrors() { for( String body : new String[] { "return p.x;", + "if (p == null) return p.x; return -1;", "if (!!points) return p.x; return -1;", "if (!!p) { int x = p.x; } return p.x;" } ) { @@ -70,7 +71,10 @@ public class Chapter10Test { new CodeGen(NULLABLE_POINT_SOURCE+body).parse().opto().typeCheck(); fail(body); } catch( RuntimeException e ) { - assertEquals(body,"Might be null accessing 'x'",e.getMessage()); + // Known null is rejected during parsing in these chapters. + String expected = body.startsWith("if (p == null)") + ? "Accessing unknown field 'x' from 'null'" : "Might be null accessing 'x'"; + assertEquals(body,expected,e.getMessage()); } } } diff --git a/chapter24/src/test/java/com/seaofnodes/simple/Chapter16Test.java b/chapter24/src/test/java/com/seaofnodes/simple/Chapter16Test.java index 2623fee5..310efc45 100644 --- a/chapter24/src/test/java/com/seaofnodes/simple/Chapter16Test.java +++ b/chapter24/src/test/java/com/seaofnodes/simple/Chapter16Test.java @@ -143,14 +143,11 @@ return p; @Test public void testStructFinal3() { - CodeGen code = new CodeGen(""" -struct Point { var x; var y; }; -Point p = new Point; -p.x++; -return p; -"""); - try { code.parse().opto(); fail(); } - catch( Exception e ) { assertEquals("'Point' is not fully initialized, field 'x' needs to be set in a constructor",e.getMessage()); } + for( String fields : new String[] { "var x; var y;", "int[] x;", "int[] !x;" } ) { + String src = "struct Point { "+fields+" }; Point p = new Point; p.x++; return p;"; + try { new CodeGen(src).parse().opto(); fail(fields); } + catch( Exception e ) { assertEquals("'Point' is not fully initialized, field 'x' needs to be set in a constructor",e.getMessage()); } + } } @Test |
