diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index 15eef7c2..b741ad58 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -157,6 +157,7 @@ public class TypeUnifyTask extends RecursiveTask>> { if(!undefinedPairs.isEmpty()) { writeLog("UndefinedPairs; " + undefinedPairs); Set> error = new HashSet<>(); + undefinedPairs = undefinedPairs.stream().map(x -> { x.setUndefinedPair(); return x;}).collect(Collectors.toCollection(HashSet::new)); error.add(undefinedPairs); return error; } @@ -296,7 +297,7 @@ public class TypeUnifyTask extends RecursiveTask>> { /* * Step 7: Filter empty sets; */ - eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x)).collect(Collectors.toCollection(HashSet::new)); + eqPrimePrimeSet = eqPrimePrimeSet.stream().filter(x -> isSolvedForm(x) || this.isUndefinedPairSet(x)).collect(Collectors.toCollection(HashSet::new)); if (!eqPrimePrimeSet.isEmpty()) writeLog("Result " + eqPrimePrimeSet.toString()); return eqPrimePrimeSet; @@ -362,7 +363,8 @@ public class TypeUnifyTask extends RecursiveTask>> { else { result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } - if (!result.isEmpty()) { + + if (!result.isEmpty() && !isUndefinedPairSetSet(result)) { if (variance == 1) { if (a.iterator().next().getLhsType().getName().equals("WL")) System.out.print(""); @@ -391,17 +393,30 @@ public class TypeUnifyTask extends RecursiveTask>> { } } } + if (nextSetasList.size() == 0 && isUndefinedPairSetSet(result)) { + return result; + } + //else result.stream().filter(y -> !isUndefinedPairSet(y)); } return result; } - protected boolean isUndefinedPairSet(Set> s) { - boolean res = true; - if (s.size() ==1) { - s.iterator().next().stream().forEach(x -> { res = res && x.isUndefinedPair(); return; }); - return res; - } + + protected boolean isUndefinedPairSet(Set s) { + Optional res = s.stream().map(x -> x.isUndefinedPair()).reduce((x,y)-> (x == y)); + if (res.isPresent()) { return res.get(); } + else { return false; } + } + + protected boolean isUndefinedPairSetSet(Set> s) { + if (s.size() ==1) { + Optional res = s.stream().map(x -> isUndefinedPairSet(x)).reduce((x,y)-> (x == y)); + if (res.isPresent()) { return res.get(); } + else { return false; } + } + return false; + } /** * Checks whether a set of pairs is in solved form. diff --git a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java index 061ba588..7b32864d 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java +++ b/src/de/dhbwstuttgart/typeinference/unify/model/Unifier.java @@ -63,7 +63,7 @@ public class Unifier implements Function, Iterable