diff --git a/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java b/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java index ad9afc7d2..f2fd7bc4a 100644 --- a/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java +++ b/src/de/dhbwstuttgart/typeinference/unifynew/RuleSet.java @@ -413,16 +413,18 @@ public class RuleSet implements IRuleSet{ newRhs = new ExtendsType(lhsType); } else { - lhsFromFc = new ExtendsType(finiteClosure.getType(((SuperType) lhsType).getSuperedType())); + lhsFromFc = new SuperType(finiteClosure.getType(((SuperType) lhsType).getSuperedType())); newRhs = new ExtendsType(((SuperType) lhsType).getSuperedType()); } - if(lhsFromFc == null) + Type rhsFromFc = finiteClosure.getType(((SuperType) rhsType).getSuperedType()); + + if(lhsFromFc == null || rhsFromFc == null) return Optional.empty(); - Set grArg = finiteClosure.grArg(lhsFromFc); + Set smArg = finiteClosure.smArg(new SuperType(rhsFromFc)); - Optional opt = grArg.stream().filter(x -> x.getName().equals(rhsType.getName())).findAny(); + Optional opt = smArg.stream().filter(x -> x.getName().equals(lhsType.getName())).findAny(); if(!opt.isPresent()) return Optional.empty(); @@ -437,6 +439,7 @@ public class RuleSet implements IRuleSet{ unif.andThen(new Unifier(lhsFromFcTypeParams.get(i), lhsTypeParams.get(i))); return Optional.of(new MPair(newLhs.apply(unif), newRhs, PairOperator.SMALLERDOTWC)); + } /** diff --git a/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java b/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java index b8910e177..92d04518e 100644 --- a/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java +++ b/src/de/dhbwstuttgart/typinference/unify/model/FiniteClosure.java @@ -92,9 +92,7 @@ public class FiniteClosure implements IFiniteClosure { Set result = new HashSet(); - Type t = inheritanceGraph.get(type).getContent(); - - result.add(t); + result.add(type); smaller(type).forEach(x -> result.add(new SuperType(x))); greater(type).forEach(x -> result.add(new ExtendsType(x))); @@ -108,7 +106,7 @@ public class FiniteClosure implements IFiniteClosure { Set result = new HashSet(); - Type t = inheritanceGraph.get(type.getExtendedType()).getContent(); + Type t = type.getExtendedType(); greater(t).forEach(x -> result.add(new ExtendsType(x))); @@ -122,7 +120,7 @@ public class FiniteClosure implements IFiniteClosure { Set result = new HashSet(); - Type t = inheritanceGraph.get(type.getSuperedType()).getContent(); + Type t = type.getSuperedType(); smaller(t).forEach(x -> result.add(new SuperType(x))); @@ -146,9 +144,7 @@ public class FiniteClosure implements IFiniteClosure { Set result = new HashSet(); - Type t = inheritanceGraph.get(type).getContent(); - - result.add(t); + result.add(type); smaller(type).forEach(x -> result.add(new ExtendsType(x))); return result; @@ -160,7 +156,7 @@ public class FiniteClosure implements IFiniteClosure { Set result = new HashSet(); - Type t = inheritanceGraph.get(type.getExtendedType()).getContent(); + Type t = type.getExtendedType(); result.add(t); smaller(t).forEach(x -> { @@ -179,7 +175,7 @@ public class FiniteClosure implements IFiniteClosure { Set result = new HashSet(); - Type t = inheritanceGraph.get(type.getSuperedType()).getContent(); + Type t = type.getSuperedType(); result.add(t); greater(t).forEach(x -> { diff --git a/test/unify/RuleSetTest.java b/test/unify/RuleSetTest.java index da8b85449..fa08b1e72 100644 --- a/test/unify/RuleSetTest.java +++ b/test/unify/RuleSetTest.java @@ -630,9 +630,12 @@ public class RuleSetTest { SimpleType t1 = tf.getSimpleType("Type1", "T", "U"); SimpleType t2 = tf.getSimpleType("Type2", "T"); SimpleType t3 = tf.getSimpleType("Type3", tf.getPlaceholderType("T"), tf.getSimpleType("Integer")); + SimpleType t32 = tf.getSimpleType("Type3", "T", "U"); + SimpleType t4 = tf.getSimpleType("Object"); fcb.add(t1, t2); fcb.add(t2, t3); + fcb.add(t32, t4); IRuleSet rules = new RuleSet(fcb.getFiniteClosure());