From 699155e21a4041bafd3d469f681c6160b3f78b78 Mon Sep 17 00:00:00 2001 From: Victorious3 Date: Sun, 3 Jul 2022 19:24:54 +0200 Subject: [PATCH] Equalize type variables in covariant and contravariant position --- .../target/generate/ASTToTargetAST.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java index 6a8e2612..a118339b 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -270,10 +270,29 @@ public class ASTToTargetAST { computedGenericsOfClasses.put(classOrInterface, result); eliminateCyclesAndInfima(result); eliminateInnerTypeVariables(classOrInterface, result); + equalizeTypeVariables(result); + System.out.println("Class " + classOrInterface.getClassName().getClassName() + ": " + result); return result; } + void equalizeTypeVariables(Set> input) { + for (var pair : new HashSet<>(input)) { + if (pair instanceof PairTPHsmallerTPH ptph) { + if (ptph.left.getVariance() == 1 && ptph.right.getVariance() == -1) { + equality.put(ptph.left, ptph.right); + input.remove(ptph); + for (var pair2 : new HashSet<>(input)) { + if (pair2 instanceof PairTPHsmallerTPH ptph2 && ptph2.right.equals(ptph.left)) { + input.remove(pair2); + input.add(new PairTPHsmallerTPH(ptph2.left, ptph.right)); + } + } + } + } + } + } + void findTphs(RefTypeOrTPHOrWildcardOrGeneric type, Set tphs) { if (type instanceof RefType refType) { refType.getParaList().forEach(t -> findTphs(t, tphs));