diff --git a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java index 14a3c7d5..43e11469 100644 --- a/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java +++ b/src/main/java/de/dhbwstuttgart/target/generate/ASTToTargetAST.java @@ -568,6 +568,8 @@ public class ASTToTargetAST { } void eliminateInnerTypeVariables(Set referenced, Set> input) { + // Remove type variables that are part of a relation A < B < C where B is not in referenced + // Add new pair A < C var oldInput = new HashSet<>(input); for (var pair : oldInput) { if (pair instanceof PairTPHsmallerTPH ptph && !referenced.contains(ptph.left)) { @@ -581,6 +583,21 @@ public class ASTToTargetAST { } } } + + // Remove lone type variables, A = RefType where A is in no relation X < A or A < X and A is not in referenced + oldInput = new HashSet<>(input); + outer: + for (var pair : oldInput) { + if (pair instanceof PairTPHequalRefTypeOrWildcardType ptph) { + if (!referenced.contains(ptph.left)) { + for (var pair2 : oldInput) { + if (pair != pair2 && (pair2.getLeft().equals(ptph.left) || pair2.getRight().equals(ptph.left))) + continue outer; + } + input.remove(pair); + } + } + } } void eliminateCycles(Set> input) {