Equalize type variables in covariant and contravariant position

This commit is contained in:
Victorious3 2022-07-03 19:24:54 +02:00
parent de417d3ee6
commit 699155e21a

View File

@ -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<ResultPair<?, ?>> 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<TypePlaceholder> tphs) {
if (type instanceof RefType refType) {
refType.getParaList().forEach(t -> findTphs(t, tphs));