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