From 64a9aec772c85a71e32409c5ef9e2271b1dade8b Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 10 Apr 2026 10:45:08 +0200 Subject: [PATCH 1/4] Failing test --- .../lang/rascalcore/compile/Examples/Tst5.rsc | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc index c287c2eb93a..c22e7c50b36 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/compile/Examples/Tst5.rsc @@ -1,2 +1,83 @@ module lang::rascalcore::compile::Examples::Tst5 +import IO; +import String; +import Location; +import Message; +import Set; +import util::Reflective; +import ParseTree; +import lang::rascalcore::check::RascalConfig; + +import lang::rascalcore::check::Checker; +import lang::rascal::\syntax::Rascal; +loc root = |memory://e0711529-477e-4a4c-b44b-44b00157728eXXX|; + +PathConfig pcfg = pathConfig( + srcs = [root + "src"], + bin = root + "bin", + libs = [] +); +// this name matters +str moduleName = "TestModule612d1"; + +loc writeModule() { + loc moduleLoc = pcfg.srcs[0] + ".rsc"; + // the spaces before &T seems to matter? + writeFile(moduleLoc, + "module TestModule612d1\r\n \r\n &T \<: int f(&T \<: num _) = 1;" + ); + return moduleLoc; +} + + + +set[Message] getErrorMessages(ModuleStatus r) + = { m | m <- getAllMessages(r), m is error }; + +set[Message] getWarningMessages(ModuleStatus r) + = { m | m <- getAllMessages(r), m is warning }; + +set[Message] getAllMessages(ModuleStatus r) + = { m | mname <- r.messages, m <- r.messages[mname] }; + +bool typecheckModule(loc m) { + status = rascalTModelForLocs([m], rascalCompilerConfig(pcfg)[infoModuleChecked=true][verbose=true], dummy_compile1); + println("All messages:"); + iprintln(getAllMessages(status)); + if (e <- getErrorMessages(status)) { + println("Errors typechecking: "); + iprintln(getErrorMessages(status)); + println("❌ Typecheck failed"); + return false; + } + else { + println("✅ Typecheck success"); + return true; + } +} + +void findCollission(loc l) { + m = parseModule(l); + locs = [ t.src | /Tree t := m, t.src?]; + println("Found locs"); + locsSet = {*locs}; + println("Became: locs when putting in set"); + for (l <- locs) { + bool found = false; + for (l2 <- locsSet, "" == "") { + found = true; + } + if (!found) { + println("❌ got dropped from set"); + } + } +} + + +void main() { + remove(root, recursive = true); + l = writeModule(); + typecheckModule(l); + findCollission(l); +} \ No newline at end of file From eca6b2ea25ab2cd2485d6f1d836199e67a3343e5 Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 10 Apr 2026 10:45:51 +0200 Subject: [PATCH 2/4] Make signature info available before collecting signature --- .../lang/rascalcore/check/CollectDeclaration.rsc | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectDeclaration.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectDeclaration.rsc index 94126613686..b50f602844d 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectDeclaration.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectDeclaration.rsc @@ -303,14 +303,10 @@ void collect(current: (FunctionDeclaration) ``, Collec c.enterLubScope(decl); collect(decl.tags, c); - = collectSignature(decl.signature, c); - //println("tpnames: "); - //iprintln("tpbounds:"); iprintln(tpbounds); - // scope = c.getScope(); c.setScopeInfo(scope, functionScope(), signatureInfo(signature.\type)); - - + = collectSignature(decl.signature, c); + dt = defType([signature], AType(Solver s) { ft = s.getType(signature); @@ -477,7 +473,7 @@ tuple[set[str], rel[str,Type]] collectSignature(Signature signature, Collector c rtU = updateBounds(rt, minB); formalsList = [ updateBounds(fm, minB) | fm <- formalsList ]; kwFormalsList = [ kwf[fieldType = updateBounds(kwf.fieldType, minB)] | kwf <- computeKwFormals(kwFormals, s) ]; - ft = afunc(rt, formalsList, kwFormalsList); + ft = afunc(rtU, formalsList, kwFormalsList); //ft = updateBounds(afunc(s.getType(returnType), formalsList, computeKwFormals(kwFormals, s)), minB); return ft; }); From 0c3f4e2b2fb3c12586d16964cd49d66a9e9e0c84 Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 10 Apr 2026 10:46:32 +0200 Subject: [PATCH 3/4] Make typed variable pattern dependent on return type - This is needed for proper execution order - This is rather coarse solution. Maybe move this to cases for type parameters? --- .../lang/rascalcore/check/CollectPattern.rsc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectPattern.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectPattern.rsc index 230d1f5f359..d9bd73f46b6 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectPattern.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectPattern.rsc @@ -93,7 +93,19 @@ void collect(current: (Pattern) ` `, Collector c){ collect(tp, c); if(tp is function) c.leaveScope(current); - c.calculate("typed variable pattern", current, [tp], AType(Solver s){ return s.getType(tp)[alabel=uname]; }); + functionScopes = c.getScopeInfo(functionScope()); + if(isEmpty(functionScopes)){ + throw rascalCheckerInternalError(getLoc(current), "No surrounding function scope found for typed variable pattern"); + } + for(<_, scopeInfo> <- functionScopes){ + if(signatureInfo(Type returnType) := scopeInfo){ + c.calculate("typed variable pattern", current, [tp, returnType], AType(Solver s){ return s.getType(tp)[alabel=uname]; }); + break; + } else { + throw rascalCheckerInternalError(getLoc(current), "Inconsistent info from function scope: "); + } + } + if(!isWildCard(uname)){ c.push(patternNames, ); orScopes = c.getScopeInfo(orScope()); From cd86eef78065a2986cebf4aa60909d6c4b022ecd Mon Sep 17 00:00:00 2001 From: paulklint Date: Fri, 10 Apr 2026 11:11:55 +0200 Subject: [PATCH 4/4] Made new dependency on returnType conditional --- .../lang/rascalcore/check/CollectPattern.rsc | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectPattern.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectPattern.rsc index d9bd73f46b6..1844b2549ba 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectPattern.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/CollectPattern.rsc @@ -92,19 +92,20 @@ void collect(current: (Pattern) ` `, Collector c){ if(tp is function) c.enterScope(current); collect(tp, c); if(tp is function) c.leaveScope(current); - + calcDeps = [tp]; functionScopes = c.getScopeInfo(functionScope()); - if(isEmpty(functionScopes)){ - throw rascalCheckerInternalError(getLoc(current), "No surrounding function scope found for typed variable pattern"); - } - for(<_, scopeInfo> <- functionScopes){ - if(signatureInfo(Type returnType) := scopeInfo){ - c.calculate("typed variable pattern", current, [tp, returnType], AType(Solver s){ return s.getType(tp)[alabel=uname]; }); - break; - } else { - throw rascalCheckerInternalError(getLoc(current), "Inconsistent info from function scope: "); + if(!isEmpty(functionScopes)){ + for(<_, scopeInfo> <- functionScopes){ + if(signatureInfo(Type returnType) := scopeInfo){ + calcDeps += returnType; + break; + } else { + throw rascalCheckerInternalError(getLoc(current), "Inconsistent info from function scope: "); + } } } + c.calculate("typed variable pattern", current, calcDeps, AType(Solver s){ return s.getType(tp)[alabel=uname]; }); + if(!isWildCard(uname)){ c.push(patternNames, );