diff --git a/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java index 203bbee09..6b450672c 100644 --- a/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java @@ -340,7 +340,7 @@ public class RuleSet implements IRuleSet{ for(int i = 0; i < lhsTypeParams.size(); i++) unif.andThen(new Unifier(lhsFromFcTypeParams.get(i), lhsTypeParams.get(i))); - return Optional.of(new MPair(newLhs.applyToTypeParams(unif), rhsType, PairOperator.SMALLERDOT)); + return Optional.of(new MPair(newLhs.apply(unif), rhsType, PairOperator.SMALLERDOT)); } @Override diff --git a/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java b/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java index 763f3107e..2b0facaf2 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/ExtendsType.java @@ -52,7 +52,7 @@ public final class ExtendsType extends Type { } @Override - public Type applyToTypeParams(Unifier unif) { - return new ExtendsType(extendedType.applyToTypeParams(unif)); + public Type apply(Unifier unif) { + return new ExtendsType(extendedType.apply(unif)); } } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java b/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java index 53d5eab3f..7b7503ee3 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/PlaceholderType.java @@ -35,7 +35,10 @@ public final class PlaceholderType extends Type{ } @Override - public Type applyToTypeParams(Unifier unif) { + public Type apply(Unifier unif) { + if(this.equals(unif.getSource())) + return unif.getTarget(); + return this; } } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/SimpleType.java b/src/de/dhbwstuttgart/typinference/unify/model/SimpleType.java index 370f472bd..8e9e8a3f4 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/SimpleType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/SimpleType.java @@ -43,7 +43,10 @@ public final class SimpleType extends Type { } @Override - public Type applyToTypeParams(Unifier unif) { + public Type apply(Unifier unif) { + if(this.equals(unif.getSource())) + return unif.getTarget(); + return new SimpleType(typeName, typeParams.apply(unif)); } } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java b/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java index 6e55a9f33..6a243e343 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/SuperType.java @@ -53,7 +53,7 @@ public final class SuperType extends Type { } @Override - public Type applyToTypeParams(Unifier unif) { - return new SuperType(superedType.applyToTypeParams(unif)); + public Type apply(Unifier unif) { + return new SuperType(superedType.apply(unif)); } } diff --git a/src/de/dhbwstuttgart/typinference/unify/model/Type.java b/src/de/dhbwstuttgart/typinference/unify/model/Type.java index b929d3c13..a9e94862b 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/Type.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/Type.java @@ -32,7 +32,7 @@ public abstract class Type { public abstract Set grArg(IFiniteClosure fc); - public abstract Type applyToTypeParams(Unifier unif); + public abstract Type apply(Unifier unif); @Override public String toString() { diff --git a/src/de/dhbwstuttgart/typinference/unify/model/TypeParams.java b/src/de/dhbwstuttgart/typinference/unify/model/TypeParams.java index fb8fcb53a..0d48e8149 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/TypeParams.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/TypeParams.java @@ -31,7 +31,7 @@ public final class TypeParams implements Iterable{ public TypeParams apply(Unifier unif) { Type[] newParams = new Type[typeParams.length]; for(int i = 0; i < typeParams.length; i++) - newParams[i] = typeParams[i].applyToTypeParams(unif); + newParams[i] = typeParams[i].apply(unif); return new TypeParams(newParams); } diff --git a/test/unify/RuleSetTest.java b/test/unify/RuleSetTest.java index f9cdce8cc..729e2ea54 100644 --- a/test/unify/RuleSetTest.java +++ b/test/unify/RuleSetTest.java @@ -518,6 +518,27 @@ public class RuleSetTest { @Test public void testAdapt() { + TypeFactory tf = new TypeFactory(); + FiniteClosureBuilder fcb = new FiniteClosureBuilder(); + + SimpleType t1 = tf.getSimpleType("Type1", "T", "U"); + SimpleType t2 = tf.getSimpleType("Type2", "T"); + SimpleType t3 = tf.getSimpleType("Type3", tf.getPlaceholderType("T"), tf.getSimpleType("Integer")); + + fcb.add(t1, t2); + fcb.add(t2, t3); + + IRuleSet rules = new RuleSet(fcb.getFiniteClosure()); + + SimpleType c1 = tf.getSimpleType("Type1", "String", "Double"); + SimpleType c2 = tf.getSimpleType("Type2", "Object"); + SimpleType c3 = tf.getSimpleType("Type3", "Object", "Number"); + + MPair pair1 = new MPair(c1, c2, PairOperator.SMALLERDOT); + MPair pair2 = new MPair(c1, c3, PairOperator.SMALLERDOT); + System.out.println("------ Adapt ------"); + System.out.println(rules.adapt(pair1)); + System.out.println(rules.adapt(pair2)); // Not working yet }