diff --git a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java index b2c9f458..3f37add1 100644 --- a/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java +++ b/src/de/dhbwstuttgart/typeinference/unify/TypeUnifyTask.java @@ -157,9 +157,9 @@ 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; - return new HashSet<>(); + return error; } /* Up to here, no cartesian products are calculated. @@ -297,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; @@ -363,11 +363,7 @@ public class TypeUnifyTask extends RecursiveTask>> { else { result.addAll(computeCartesianRecursive(elems, remainingSets, eq, fc, parallel)); } - //if (result.size() == 1) { - // System.out.println(result.toString()); - // result.remove(result.iterator().next()); - //} - if (!result.isEmpty()) { + if (!result.isEmpty() && !isUndefinedPairSetSet(result)) { if (variance == 1) { if (a.iterator().next().getLhsType().getName().equals("WL")) System.out.print(""); @@ -396,10 +392,29 @@ 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) { + + 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. * @param eqPrimePrime The set of pair 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