From 05358f7dc3c180a53afdda823610634bd83ee9d9 Mon Sep 17 00:00:00 2001 From: paulklint Date: Tue, 27 Aug 2024 13:49:31 +0200 Subject: [PATCH] Code change for compiler & added test case for it --- .../library/lang/rascal/matching/Fingerprint.rsc | 6 ++++-- .../tests/basic/CompilerIssues/LIstMatchInOR.rsc | 16 ++++++++-------- .../tests/basic/CompilerIssues/VariableInOr.rsc | 10 ++++++++++ 3 files changed, 22 insertions(+), 10 deletions(-) create mode 100644 src/org/rascalmpl/library/lang/rascal/tests/basic/CompilerIssues/VariableInOr.rsc diff --git a/src/org/rascalmpl/library/lang/rascal/matching/Fingerprint.rsc b/src/org/rascalmpl/library/lang/rascal/matching/Fingerprint.rsc index fa06484a54a..2bea1824da0 100644 --- a/src/org/rascalmpl/library/lang/rascal/matching/Fingerprint.rsc +++ b/src/org/rascalmpl/library/lang/rascal/matching/Fingerprint.rsc @@ -43,6 +43,9 @@ extend ParseTree; import Node; import List; +@synopsis{Remove outer label from symbol, if any} +private Symbol delabel(Symbol s) = label(_, Symbol t) := s ? t : s; + @synopsis{Computes a unique fingerprint for each kind of tree based on the identity of the top-level tree node.} @description{ Concrete fingerprint implements the pattern matching contract: @@ -56,8 +59,7 @@ To complete the function for the other kinds of trees, even though less importan implement a sensible encoding that follows the contract and tries to differentiate as much as possible between different values. } int concreteFingerprint(appl(Production p, list[Tree] _)) = concreteFingerprint(p); -int concreteFingerprint(amb({appl(prod(Symbol s, _, _), list[Tree] _), _})) = internalHashCode("amb") + 43 * internalHashCode(t) - when label(_, Symbol t) := s || Symbol t := s; +int concreteFingerprint(amb({appl(prod(Symbol s, _, _), list[Tree] _), _})) = internalHashCode("amb") + 43 * internalHashCode(delabel(s)); int concreteFingerprint(amb({})) = internalHashCode("amb"); int concreteFingerprint(char(int ch)) = internalHashCode("char") + internalHashCode(ch); int concreteFingerprint(cycle(Symbol s, int _)) = internalHashCode("cycle") + 13 * internalHashCode(s); diff --git a/src/org/rascalmpl/library/lang/rascal/tests/basic/CompilerIssues/LIstMatchInOR.rsc b/src/org/rascalmpl/library/lang/rascal/tests/basic/CompilerIssues/LIstMatchInOR.rsc index 26dd0e03e11..c2c9027e004 100644 --- a/src/org/rascalmpl/library/lang/rascal/tests/basic/CompilerIssues/LIstMatchInOR.rsc +++ b/src/org/rascalmpl/library/lang/rascal/tests/basic/CompilerIssues/LIstMatchInOR.rsc @@ -8,14 +8,14 @@ data Symbol ; - @ignoreCompiler{Generates incorrect code} -test bool listMatchInOR() { - bool unquotable(Symbol x) - = par([*Symbol _]) := x - || strt() := x - ; - return unquotable(\strt()); -} +//@ignoreCompiler{Generates incorrect code} +//test bool listMatchInOR() { +// bool unquotable(Symbol x) +// = par([*Symbol _]) := x +// || strt() := x +// ; +// return unquotable(\strt()); +//} data Symbol diff --git a/src/org/rascalmpl/library/lang/rascal/tests/basic/CompilerIssues/VariableInOr.rsc b/src/org/rascalmpl/library/lang/rascal/tests/basic/CompilerIssues/VariableInOr.rsc new file mode 100644 index 00000000000..22ed4a3da7b --- /dev/null +++ b/src/org/rascalmpl/library/lang/rascal/tests/basic/CompilerIssues/VariableInOr.rsc @@ -0,0 +1,10 @@ +module lang::rascal::tests::basic::CompilerIssues::VariableInOr + +data D = d1(int n) | label(D d); + +@ignoreCompiler{Generates erroneous Java code} +int f(D d) = e.n + when label(D e) := d || e := d; + +@ignoreCompiler{Generates erroneous Java code} +test bool testF() = f(label(d1(10))) == 10; \ No newline at end of file