diff options
| author | Cliff Click <cliffc@acm.org> | 2025-05-06 13:44:10 -0700 |
|---|---|---|
| committer | Cliff Click <cliffc@acm.org> | 2025-07-08 20:29:09 -0700 |
| commit | 664761624f4b0e3d6d1593b99e576854beec5949 (patch) | |
| tree | edff0e36e07cdc5aa82c8f7d144d68c52d5a4365 /src/test/java/com/seaofnodes/simple/Chapter16Test.java | |
| parent | 018379b0cf4e286ceacb1e39f34dd80f770e381e (diff) | |
| download | Simple-linear-chapter23.tar.gz Simple-linear-chapter23.zip | |
Chapter 23: Methods and Revisiting Typeslinear-chapter23
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/Chapter16Test.java')
| -rw-r--r-- | src/test/java/com/seaofnodes/simple/Chapter16Test.java | 16 |
1 files changed, 7 insertions, 9 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter16Test.java b/src/test/java/com/seaofnodes/simple/Chapter16Test.java index 58bb4148..2623fee5 100644 --- a/src/test/java/com/seaofnodes/simple/Chapter16Test.java +++ b/src/test/java/com/seaofnodes/simple/Chapter16Test.java @@ -1,8 +1,6 @@ package com.seaofnodes.simple; import com.seaofnodes.simple.codegen.CodeGen; -import com.seaofnodes.simple.evaluator.Evaluator; -import com.seaofnodes.simple.node.StopNode; import org.junit.Test; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; @@ -115,7 +113,7 @@ Point p = new Point { x=3; y=4; }; return p; """); code.parse().opto(); - assertEquals("return (const)Point;", code.print()); + assertEquals("return Point;", code.print()); assertEquals("Point{x=3,y=4}", Eval2.eval(code, 0)); } @@ -123,24 +121,24 @@ return p; public void testStructFinal1() { CodeGen code = new CodeGen(""" struct Point { int x=3, y=4; }; -Point p = new Point { x=5; y=6; }; +val p = new Point { x=5; y=6; }; p.x++; return p; """); try { code.parse().opto().typeCheck(); fail(); } - catch( Exception e ) { assertEquals("Cannot reassign final 'x'",e.getMessage()); } + catch( Exception e ) { assertEquals("Cannot modify final field 'x'",e.getMessage()); } } @Test public void testStructFinal2() { CodeGen code = new CodeGen(""" struct Point { int x=3, y=4; }; -Point p = new Point; +val p = new Point; p.x++; return p; """); try { code.parse().opto().typeCheck(); fail(); } - catch( Exception e ) { assertEquals("Cannot reassign final 'x'",e.getMessage()); } + catch( Exception e ) { assertEquals("Cannot modify final field 'x'",e.getMessage()); } } @Test @@ -163,8 +161,8 @@ Point p = new Point; p.x++; return p; """); - try { code.parse().opto(); fail(); } - catch( Exception e ) { assertEquals("Cannot reassign final 'x'",e.getMessage()); } + try { code.parse().opto().typeCheck(); fail(); } + catch( Exception e ) { assertEquals("Cannot modify final field 'x'",e.getMessage()); } } @Test |
