From 09b016d2c2d38e161960012480975bd91edaeab8 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 15 Jun 2026 13:32:23 +0200 Subject: [PATCH 1/2] Add test (currently fails) for issue that `tm.uses` is empty in TModels produced by the Rascal typechecker --- .../rascalcore/check/tests/StaticTestingUtils.rsc | 3 +++ .../lang/rascalcore/check/tests/UseDefTests.rsc | 12 +++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc index e6f587d002..6be1ae6b34 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/StaticTestingUtils.rsc @@ -247,6 +247,9 @@ bool validateUseDefs(str moduleName, map[str, tuple[int, set[int]]] defuses, Mod if(!occ[u]?){ throw "Missing use for "; } + if(!any(use <- tm.uses, occ[u] == use.occ)){ + throw "Missing `Use` value for use of "; + } potentialDefs = foundUseDefs[occ[u]]; if(isEmpty(potentialDefs) || !any(d <- potentialDefs, occ[def] == (tm.logical2physical[d] ? d))){ throw "Missing def for use of "; diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/UseDefTests.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/UseDefTests.rsc index 8a812d2854..81b41d5a95 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/UseDefTests.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/UseDefTests.rsc @@ -107,4 +107,14 @@ test bool overloadedSyntaxField(){ return useDefOK(mtext, ("c": <0, {2}>)) // check uses of first declaration of c && useDefOK(mtext, ("c": <1, {3}>)) // check uses of first declaration of c ; -} \ No newline at end of file +} + +test bool issue2165() = + useDefOK("module Issue2165 + int f(int i) { + int x = 2; + return i * x; + } + void main() { + f(5); + }", ("x": <0, {1}>, "i": <0, {1}>, "f": <0, {1}>)); \ No newline at end of file From e637cb7897cc7bf07ba10ecbd1b4b0e3ac02f148 Mon Sep 17 00:00:00 2001 From: Sung-Shik Jongmans Date: Mon, 15 Jun 2026 13:38:50 +0200 Subject: [PATCH 2/2] Fix issue that `tm.uses` was empty in TModels produced by the Rascal typechecker --- src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc | 1 + .../compiler/lang/rascalcore/check/tests/UseDefTests.rsc | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc index 6b39268e7e..0c2bcb77be 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/Import.rsc @@ -505,6 +505,7 @@ ModuleStatus doSaveModule(set[MODID] component, map[MODID,set[MODID]] m_imports, } }; + m1.uses = [u | Use u <- tm.uses, u.occ in m1.useDef<0>]; m1.defines = toSet(defs); m1.definitions = ( def.defined : def | Define def <- m1.defines); // TODO this is derived info, can we derive it later? diff --git a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/UseDefTests.rsc b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/UseDefTests.rsc index 81b41d5a95..a85dd06248 100644 --- a/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/UseDefTests.rsc +++ b/src/org/rascalmpl/compiler/lang/rascalcore/check/tests/UseDefTests.rsc @@ -110,11 +110,11 @@ test bool overloadedSyntaxField(){ } test bool issue2165() = - useDefOK("module Issue2165 + useDefOK("module Issue2165 int f(int i) { int x = 2; return i * x; } void main() { f(5); - }", ("x": <0, {1}>, "i": <0, {1}>, "f": <0, {1}>)); \ No newline at end of file + }", ("x": <0, {1}>, "i": <0, {1}>, "f": <0, {1}>));