diff --git a/src/org/rascalmpl/values/RascalValueFactory.java b/src/org/rascalmpl/values/RascalValueFactory.java index 69911110028..65a76ca1f6d 100644 --- a/src/org/rascalmpl/values/RascalValueFactory.java +++ b/src/org/rascalmpl/values/RascalValueFactory.java @@ -20,6 +20,7 @@ import java.util.function.Supplier; import org.rascalmpl.parser.gtd.util.ArrayList; +import org.rascalmpl.types.NonTerminalType; import org.rascalmpl.types.RascalTypeFactory; import org.rascalmpl.types.TypeReifier; import org.rascalmpl.values.parsetrees.ITree; @@ -1050,18 +1051,13 @@ public Amb(ISet alts) { @Override public int getConcreteMatchFingerprint() { - return 96694 /* "amb".hashCode() */ + 43 * alternatives.getElementType().hashCode(); + return 96694 /* "amb".hashCode() */ + 43 * ((NonTerminalType) alternatives.getElementType()).getSymbol().hashCode(); } @Override public boolean isAmb() { return true; } - - @Override - public int getMatchFingerprint() { - return 96694 /* Tree_Amb.getName().hashCode() */ + 131; // should be equal what IConstructor does for the amb constructor! - } @Override public ITree accept(TreeVisitor v) throws E { diff --git a/test/org/rascalmpl/MatchFingerprintTest.java b/test/org/rascalmpl/MatchFingerprintTest.java index 72674cde85a..c0b3001c43b 100644 --- a/test/org/rascalmpl/MatchFingerprintTest.java +++ b/test/org/rascalmpl/MatchFingerprintTest.java @@ -67,7 +67,7 @@ public void testTreeApplFingerPrintStability() { IConstructor prod = (IConstructor) new StandardTextReader().read(VF, RascalFunctionValueFactory.getStore(), RascalFunctionValueFactory.Production, new StringReader(prodString)); ITree tree = VF.appl(prod, VF.list()); - assertEquals(tree.getMatchFingerprint(), "prod".hashCode() + 131 * prod.arity()); + assertEquals(tree.getMatchFingerprint(), "appl".hashCode() + 131 * 2); assertEquals(tree.getConcreteMatchFingerprint(), "tree".hashCode() + 41 * prod.hashCode()); } catch (FactTypeUseException | IOException e) { @@ -76,15 +76,19 @@ public void testTreeApplFingerPrintStability() { } public void testTreeAmbFingerPrintStability() { - String prodString = "prod(sort(\"E\"),[],{})"; + String prodString1 = "prod(sort(\"E\"),[],{})"; + String prodString2 = "prod(sort(\"E\"),[empty()],{})"; try { - IConstructor prod = (IConstructor) new StandardTextReader().read(VF, RascalFunctionValueFactory.getStore(), RascalFunctionValueFactory.Production, new StringReader(prodString)); - ITree tree = VF.appl(prod, VF.list()); - ITree amb = VF.amb(VF.set(tree)); + IConstructor prod1= (IConstructor) new StandardTextReader().read(VF, RascalFunctionValueFactory.getStore(), RascalFunctionValueFactory.Production, new StringReader(prodString1)); + ITree tree1 = VF.appl(prod1, VF.list()); + IConstructor prod2= (IConstructor) new StandardTextReader().read(VF, RascalFunctionValueFactory.getStore(), RascalFunctionValueFactory.Production, new StringReader(prodString2)); + ITree tree2 = VF.appl(prod2, VF.list()); + + ITree amb = VF.amb(VF.set(tree1, tree2)); assertEquals(amb.getMatchFingerprint(), "amb".hashCode() + 131); - assertEquals(tree.getConcreteMatchFingerprint(), "amb".hashCode() + 43 * TreeAdapter.getType(amb).hashCode()); + assertEquals(amb.getConcreteMatchFingerprint(), "amb".hashCode() + 43 * TreeAdapter.getType(amb).hashCode()); } catch (FactTypeUseException | IOException e) { fail(e.getMessage());