summaryrefslogtreecommitdiff
path: root/src/test/java/com/seaofnodes/simple/Chapter17Test.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/com/seaofnodes/simple/Chapter17Test.java')
-rw-r--r--src/test/java/com/seaofnodes/simple/Chapter17Test.java35
1 files changed, 18 insertions, 17 deletions
diff --git a/src/test/java/com/seaofnodes/simple/Chapter17Test.java b/src/test/java/com/seaofnodes/simple/Chapter17Test.java
index bdeb645c..53c23ecd 100644
--- a/src/test/java/com/seaofnodes/simple/Chapter17Test.java
+++ b/src/test/java/com/seaofnodes/simple/Chapter17Test.java
@@ -123,8 +123,8 @@ return s.x;
@Test public void testInt10() {
CodeGen code = new CodeGen("flt x = 1.5; x++; int i = x; return i;");
- try { code.parse().opto(); fail(); }
- catch( Exception e ) { assertEquals("Type 2.5f is not of declared type int",e.getMessage()); }
+ try { code.parse().opto().typeCheck(); fail(); }
+ catch( Exception e ) { assertEquals("Type 2.5f is not of declared type i64",e.getMessage()); }
}
@@ -170,15 +170,15 @@ return s.x;
}
@Test public void testVar6() {
- CodeGen code = new CodeGen("struct S{int x;}; S s=new S; s.x++; return s.x; // Error initializer so x is immutable ");
+ CodeGen code = new CodeGen("struct S{int x;}; val s = new S; s.x++; return s.x; // Error initializer so x is immutable ");
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 testVar7() {
- CodeGen code = new CodeGen("struct S{int x;}; S s=new S{x=3;}; s.x++; return s.x; // Error initializer so x is immutable ");
+ CodeGen code = new CodeGen("struct S{int x;}; val s = new S{x=3;}; s.x++; return s.x; // Error initializer so x is immutable ");
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 testVar8() {
@@ -198,7 +198,7 @@ return s.x;
@Test public void testVar10() {
CodeGen code = new CodeGen("struct S{int x;}; val s=new S; s.x++; return s.x; // Error, has val so x is immutable ");
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 testVar11() {
@@ -214,9 +214,10 @@ foo.bar.x++; // Ok foo and foo.bar and foo.bar.x are all mutable
val xfoo = foo; // Throw away mutability
xfoo.bar.x++; // Error, cannot mutate through xfoo
+return xfoo.bar.x;
""");
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 testVar12() {
@@ -274,7 +275,7 @@ return new A {
if (arg) b = new B; // Constructor ends with partial init of b
}.b;
""");
- try { code.parse().opto(); fail(); }
+ try { code.parse(); fail(); }
catch( Exception e ) { assertEquals("'A' is not fully initialized, field 'b' needs to be set in a constructor",e.getMessage()); }
}
@@ -307,7 +308,7 @@ focus(me);
return me;
"""
);
- try { code.parse().opto().typeCheck(); fail(); }
+ try { code.parse(); fail(); }
catch( Exception e ) { assertEquals("Syntax error, expected =expression: ;",e.getMessage()); }
}
@@ -491,15 +492,15 @@ return new A;
@Test
public void testForward1() {
CodeGen code = new CodeGen("""
-struct A{
+struct A {
B?[]? nil_array_of_b;
- B?[] not_array_of_b = new B?[0];
+ B?[] array_of_b;
};
-return new A.not_array_of_b;
+return new A{array_of_b = new B?[0]; }.array_of_b;
""");
code.parse().opto();
- assertEquals("return (const)[*B?];", code.print());
- assertEquals("*B?[]", Eval2.eval(code,0));
+ assertEquals("return (const)[]*B?;", code.print());
+ assertEquals("*B {... }?[]", Eval2.eval(code,0));
}
// ---------------------------------------------------------------
@@ -548,8 +549,8 @@ for( int j=0; j<nprimes; j++ )
return rez;
""");
code.parse().opto().typeCheck().GCM();
- assertEquals("return [int];", code.print());
- assertEquals("int[ 2,3,5,7,11,13,17,19]",Eval2.eval(code, 20));
+ assertEquals("return []i64;", code.print());
+ assertEquals("i64[ 2,3,5,7,11,13,17,19]",Eval2.eval(code, 20));
}
}