Skip to content

Commit

Permalink
fixed a bug that let the test fail
Browse files Browse the repository at this point in the history
  • Loading branch information
jurgenvinju committed Nov 2, 2023
1 parent afe38a0 commit 879bff9
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/org/rascalmpl/values/RascalValueFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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 <E extends Throwable> ITree accept(TreeVisitor<E> v) throws E {
Expand Down
16 changes: 10 additions & 6 deletions test/org/rascalmpl/MatchFingerprintTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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());
Expand Down

0 comments on commit 879bff9

Please sign in to comment.