forked from JavaTX/JavaCompilerCore
TestContraVariant
This commit is contained in:
parent
f8f76e9f7d
commit
8992260264
@ -1,6 +1,7 @@
|
||||
public class TestContraVariant {
|
||||
main(x) {
|
||||
return x;
|
||||
var pair = m(x);
|
||||
return pair.a;
|
||||
}
|
||||
|
||||
m(x) {
|
||||
|
@ -206,8 +206,10 @@ public class ASTToTargetAST {
|
||||
if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
|
||||
continue;
|
||||
for (var pair : simplifiedConstraints) {
|
||||
if (pair.left.equals(typeVariable) && typeVariables.contains(pair.right)) {
|
||||
addToPairs(result, new PairTPHsmallerTPH(pair.left, equality.getOrDefault(pair.right, pair.right)));
|
||||
var left = equality.getOrDefault(pair.left, pair.left);
|
||||
var right = equality.getOrDefault(pair.right, pair.right);
|
||||
if (left.equals(typeVariable) && typeVariables.contains(right)) {
|
||||
addToPairs(result, new PairTPHsmallerTPH(left, right));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -249,7 +251,6 @@ public class ASTToTargetAST {
|
||||
if (optMethod.isEmpty()) return;
|
||||
var method = optMethod.get();
|
||||
var generics = generics(owner, method);
|
||||
System.out.println("Generics: " + generics);
|
||||
|
||||
// transitive and
|
||||
var all = transitiveClosure(generics);
|
||||
@ -365,13 +366,16 @@ public class ASTToTargetAST {
|
||||
var closure = transitiveClosure((Set) simplifiedConstraints);
|
||||
// Type variables with bounds that are also type variables of the class
|
||||
for (var typeVariable : new HashSet<>(typeVariables)) {
|
||||
typeVariable = equality.getOrDefault(typeVariable, typeVariable);
|
||||
if (typeVariablesOfClass.contains(typeVariable)) continue;
|
||||
|
||||
var pairs = new HashSet<PairTPHsmallerTPH>();
|
||||
for (var pair : closure) {
|
||||
if (!(pair instanceof PairTPHsmallerTPH ptph)) continue;
|
||||
if (ptph.left.equals(typeVariable) && typeVariablesOfClass.contains(ptph.right)) {
|
||||
pairs.add(new PairTPHsmallerTPH(ptph.left, equality.getOrDefault(ptph.right, ptph.right)));
|
||||
var left = equality.getOrDefault(ptph.left, ptph.left);
|
||||
var right = equality.getOrDefault(ptph.right, ptph.right);
|
||||
if (left.equals(typeVariable) && typeVariablesOfClass.contains(right)) {
|
||||
pairs.add(new PairTPHsmallerTPH(left, right));
|
||||
}
|
||||
}
|
||||
|
||||
@ -402,12 +406,16 @@ public class ASTToTargetAST {
|
||||
}
|
||||
|
||||
if (minimalPair != null)
|
||||
addToPairs(result, minimalPair);
|
||||
addToPairs(result, new PairTPHsmallerTPH(
|
||||
equality.getOrDefault(minimalPair.left, minimalPair.left),
|
||||
equality.getOrDefault(minimalPair.right, minimalPair.right)
|
||||
));
|
||||
}
|
||||
|
||||
// All unbounded type variables (bounds not in method)
|
||||
outer:
|
||||
for (var typeVariable : typeVariables) {
|
||||
typeVariable = equality.getOrDefault(typeVariable, typeVariable);
|
||||
if (classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, typeVariable))
|
||||
continue;
|
||||
for (var pair : result) {
|
||||
@ -420,12 +428,13 @@ public class ASTToTargetAST {
|
||||
// All unbounded bounds
|
||||
outer:
|
||||
for (var pair : simplifiedConstraints) {
|
||||
var r = equality.getOrDefault(pair.right, pair.right);
|
||||
for (var pair2 : simplifiedConstraints) {
|
||||
if (pair.right.equals(pair2.left))
|
||||
if (r.equals(equality.getOrDefault(pair2.left, pair2.left)))
|
||||
continue outer;
|
||||
}
|
||||
if (!classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, pair.right) && typeVariables.contains(pair.right)) {
|
||||
addToPairs(result, new PairTPHequalRefTypeOrWildcardType(pair.right, OBJECT));
|
||||
if (!classHasGeneric(userDefinedGenericsOfClass, typeVariablesOfClass, r) && typeVariables.contains(r)) {
|
||||
addToPairs(result, new PairTPHequalRefTypeOrWildcardType(r, OBJECT));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user