From bdaf578f86f493836e0a2e8a84005370f9e470a9 Mon Sep 17 00:00:00 2001 From: Daniel Holle Date: Tue, 27 Jun 2023 15:48:15 +0200 Subject: [PATCH] Fix equality --- .../target/generate/GenerateGenerics.java | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/dhbwstuttgart/target/generate/GenerateGenerics.java b/src/main/java/de/dhbwstuttgart/target/generate/GenerateGenerics.java index 9c4b1439..8c06b5d6 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/GenerateGenerics.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/GenerateGenerics.java @@ -14,6 +14,7 @@ import de.dhbwstuttgart.typeinference.result.PairTPHEqualTPH; import de.dhbwstuttgart.typeinference.result.PairTPHequalRefTypeOrWildcardType; import de.dhbwstuttgart.typeinference.result.PairTPHsmallerTPH; import de.dhbwstuttgart.typeinference.result.ResultSet; +import de.dhbwstuttgart.util.Pair; import java.util.*; import java.util.stream.Collectors; @@ -657,7 +658,12 @@ public abstract class GenerateGenerics { } } + private record ToAdd(TypePlaceholder left, TypePlaceholder right) {} + void equalizeTypeVariables(Set input, Set referenced) { + + var elementsToAddToEquality = new ArrayList(); + for (var pair : new HashSet<>(input)) { if (pair instanceof PairLT ptph && referenced.contains(ptph.left)) { var chain = new ArrayList(); @@ -698,7 +704,8 @@ public abstract class GenerateGenerics { for (var i = 1; i < index; i++) { var cur = chain.get(i); if (!referenced.contains(cur)) continue; - addToEquality(cur.resolve(), start.resolve(), referenced); + elementsToAddToEquality.add(new ToAdd(cur.resolve(), start.resolve())); + //addToEquality(cur.resolve(), start.resolve(), referenced); TPH finalPrev = prev; input.removeIf(p -> p.equals(new PairLT(finalPrev, cur))); for (var pair2 : new HashSet<>(input)) { @@ -712,6 +719,11 @@ public abstract class GenerateGenerics { } } } + + for (var pair : elementsToAddToEquality) { + System.out.println(pair); + addToEquality(pair.left, pair.right, referenced); + } } void findTphs(RefTypeOrTPHOrWildcardOrGeneric type, Set tphs) { @@ -894,6 +906,8 @@ public abstract class GenerateGenerics { } } newTph.setVariance(variance); + System.out.println(infima + " " + infima.stream().map(i -> i.right.resolve().getVariance()).toList()); + System.out.println("Infima new TPH " + newTph + " variance " + variance); //referenced.add(newTph); addToPairs(input, new PairLT(left, new TPH(newTph)));