summaryrefslogtreecommitdiff
path: root/chapter33/src/test/java
diff options
context:
space:
mode:
authorCliff Click <cliffc@acm.org>2026-12-04 14:17:54 -0800
committerCliff Click <cliffc@acm.org>2026-12-04 14:17:54 -0800
commit89d973c785f86974c52c64ee746bf3d58751fa1d (patch)
tree22995fc75782e16feb52cfd957e50b71c6931cf7 /chapter33/src/test/java
parent4c7e14994856e5d3218dd7d909d6a848be15753d (diff)
downloadSimple-89d973c785f86974c52c64ee746bf3d58751fa1d.tar.gz
Simple-89d973c785f86974c52c64ee746bf3d58751fa1d.zip
Parse complete qualified forward type names in type contexts
Consume nested type names through open definitions and forward references, including new expressions. Resolve expression primaries separately so dotted member access remains a sequence of loads. Commit forward types only after recognizing a type context. Validation: reproduced two parsing failures before the fix. Four qualified-name regressions and the complete make -k -j8 tests suite pass (825 executions).
Diffstat (limited to 'chapter33/src/test/java')
-rw-r--r--chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java55
1 files changed, 55 insertions, 0 deletions
diff --git a/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java b/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java
index 99dc4452..b625f989 100644
--- a/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java
+++ b/chapter33/src/test/java/com/seaofnodes/simple/Chapter33Test.java
@@ -3,6 +3,9 @@ package com.seaofnodes.simple;
import com.seaofnodes.simple.codegen.CodeGen;
import com.seaofnodes.simple.node.*;
import com.seaofnodes.simple.util.WorkList;
+import com.seaofnodes.simple.type.TypeInteger;
+import java.nio.file.Files;
+import java.nio.file.Path;
import org.junit.Test;
import static org.junit.Assert.*;
@@ -41,4 +44,56 @@ public class Chapter33Test {
assertTrue(rewritten.isDead());
assertEquals("42",Eval2.eval(code,42));
}
+ // Reduced from Clock: the preceding qualified new used to leave only
+ // a sys placeholder, causing the parameter to stop at the first dot.
+ @Test public void testSourceQualifiedCanvasParameter() throws Exception {
+ Path out=Files.createTempDirectory(Files.createDirectories(Path.of("build/objs")),"canvas-source-");
+ CodeGen code=new CodeGen("src/main/smp",out.toString(),null,"Clock","""
+ val _survey_sys = sys;
+ val main = { -> new sys.draw.Canvas(320,240); };
+ val _draw = { sys.draw.Canvas screen -> screen.width; };
+ return 0;
+ """,456,true,TypeInteger.BOT);
+ code.driver(CodeGen.Phase.Parse);
+ }
+
+ @Test public void testQualifiedForwardTypeChain() {
+ CodeGen code=new CodeGen("""
+ val make={ -> new A.B.C.D(); };
+ val read={ A.B.C.D d -> d.x; };
+ A.B.C.D? saved=null;
+ struct A { struct B { struct C { struct D { int x=42; }; }; }; };
+ return read(make());
+ """).driver(CodeGen.Phase.TypeCheck);
+ assertEquals("42",Eval2.eval(code,0));
+ }
+
+ @Test public void testQualifiedTypeThroughOpenDefinition() {
+ CodeGen code=new CodeGen("""
+ struct A {
+ val make={ -> new A.B.C.D(); };
+ struct B { struct C { struct D { int x=42; }; }; };
+ };
+ return new A.make().x;
+ """).driver(CodeGen.Phase.TypeCheck);
+ assertEquals("42",Eval2.eval(code,0));
+ }
+
+ @Test public void testQualifiedExpressionIsMemberAccess() throws Exception {
+ Path root=Files.createTempDirectory(Files.createDirectories(Path.of("build/objs")),"qualified-expr-");
+ Files.createDirectories(root.resolve("sys/draw"));
+ Files.writeString(root.resolve("sys.smp"),"val draw=draw;");
+ Files.writeString(root.resolve("sys/draw.smp"),"val Canvas=Canvas;");
+ Files.writeString(root.resolve("sys/draw/Canvas.smp"),"int foo=42;");
+ CodeGen code=new CodeGen(root.toString(),root.resolve("obj").toString(),null,"Clock","""
+ val keep=sys;
+ sys.draw.Canvas.foo;
+ if( sys.draw.Canvas.foo ) return sys.draw.Canvas.foo;
+ return 0;
+ """,456,true,TypeInteger.BOT).driver(CodeGen.Phase.TypeCheck);
+ assertEquals("42",Eval2.eval(code,0));
+ for( String name : com.seaofnodes.simple.parser.Parser.TYPES.keySet() )
+ assertFalse("Expression lookahead created a type: "+name,name.endsWith(".foo"));
+ }
+
}