From 89d973c785f86974c52c64ee746bf3d58751fa1d Mon Sep 17 00:00:00 2001 From: Cliff Click Date: Fri, 4 Dec 2026 14:17:54 -0800 Subject: 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). --- .../java/com/seaofnodes/simple/Chapter33Test.java | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) (limited to 'chapter33/src/test/java') 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")); + } + } -- cgit v1.2.3