forked from JavaTX/JavaCompilerCore
adapt + tests
This commit is contained in:
parent
3739747eca
commit
e447e1cd46
@ -319,6 +319,9 @@ public class RuleSet implements IRuleSet{
|
|||||||
if(lhsType.getTypeParams().size() == 0 || rhsType.getTypeParams().size() == 0)
|
if(lhsType.getTypeParams().size() == 0 || rhsType.getTypeParams().size() == 0)
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
|
|
||||||
|
if(lhsType.getName().equals(rhsType.getName()))
|
||||||
|
return Optional.empty();
|
||||||
|
|
||||||
Type lhsFromFc = finiteClosure.getType(lhsType.getName());
|
Type lhsFromFc = finiteClosure.getType(lhsType.getName());
|
||||||
|
|
||||||
if(lhsFromFc == null)
|
if(lhsFromFc == null)
|
||||||
@ -337,7 +340,7 @@ public class RuleSet implements IRuleSet{
|
|||||||
TypeParams lhsFromFcTypeParams = lhsFromFc.getTypeParams();
|
TypeParams lhsFromFcTypeParams = lhsFromFc.getTypeParams();
|
||||||
|
|
||||||
Unifier unif = new Unifier(lhsFromFcTypeParams.get(0), lhsTypeParams.get(0));
|
Unifier unif = new Unifier(lhsFromFcTypeParams.get(0), lhsTypeParams.get(0));
|
||||||
for(int i = 0; i < lhsTypeParams.size(); i++)
|
for(int i = 1; i < lhsTypeParams.size(); i++)
|
||||||
unif.andThen(new Unifier(lhsFromFcTypeParams.get(i), lhsTypeParams.get(i)));
|
unif.andThen(new Unifier(lhsFromFcTypeParams.get(i), lhsTypeParams.get(i)));
|
||||||
|
|
||||||
return Optional.of(new MPair(newLhs.apply(unif), rhsType, PairOperator.SMALLERDOT));
|
return Optional.of(new MPair(newLhs.apply(unif), rhsType, PairOperator.SMALLERDOT));
|
||||||
|
@ -538,8 +538,15 @@ public class RuleSetTest {
|
|||||||
MPair pair2 = new MPair(c1, c3, PairOperator.SMALLERDOT);
|
MPair pair2 = new MPair(c1, c3, PairOperator.SMALLERDOT);
|
||||||
System.out.println("------ Adapt ------");
|
System.out.println("------ Adapt ------");
|
||||||
System.out.println(rules.adapt(pair1));
|
System.out.println(rules.adapt(pair1));
|
||||||
System.out.println(rules.adapt(pair2)); // Not working yet
|
System.out.println(rules.adapt(pair2));
|
||||||
|
|
||||||
|
MPair noAdapt1 = new MPair(c2, c1, PairOperator.SMALLERDOT);
|
||||||
|
MPair noAdapt2 = new MPair(c1, c1, PairOperator.SMALLERDOT);
|
||||||
|
MPair noAdapt3 = new MPair(c1, c2, PairOperator.SMALLERDOTWC);
|
||||||
|
|
||||||
|
Assert.assertFalse(rules.adapt(noAdapt1).isPresent());
|
||||||
|
Assert.assertFalse(rules.adapt(noAdapt2).isPresent());
|
||||||
|
Assert.assertFalse(rules.adapt(noAdapt3).isPresent());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
Reference in New Issue
Block a user