Skip to content

Commit

Permalink
Correct capture type variable method
Browse files Browse the repository at this point in the history
  • Loading branch information
smillst authored Aug 12, 2021
1 parent 2d64c76 commit 42ceca4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4992,7 +4992,8 @@ public List<AnnotatedTypeVariable> order(Collection<AnnotatedTypeVariable> colle

/**
* Returns the first TypeVariable in {@code collection} that does not lexically contain any other
* type in the collection.
* type in the collection. Or if all the TypeVariables contain another, then it returns the first
* TypeVariable in {@code collection}.
*
* @param collection a collection of type variables
* @return the first TypeVariable in {@code collection} that does not contain any other type in
Expand All @@ -5001,7 +5002,11 @@ public List<AnnotatedTypeVariable> order(Collection<AnnotatedTypeVariable> colle
@SuppressWarnings("interning:not.interned") // must be the same object from collection
private AnnotatedTypeVariable doesNotContainOthers(
Collection<? extends AnnotatedTypeVariable> collection) {
AnnotatedTypeVariable first = null;
for (AnnotatedTypeVariable candidate : collection) {
if (first == null) {
first = candidate;
}
boolean doesNotContain = true;
for (AnnotatedTypeVariable other : collection) {
if (candidate != other && captureScanner.visit(candidate, other.getUnderlyingType())) {
Expand All @@ -5013,7 +5018,7 @@ private AnnotatedTypeVariable doesNotContainOthers(
return candidate;
}
}
throw new BugInCF("Not found: %s", StringsPlume.join(",", collection));
return first;
}

/**
Expand Down
10 changes: 10 additions & 0 deletions framework/tests/all-systems/Issue4852.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@SuppressWarnings("all") // Just check for crashes.
public class Issue4852 {
interface Class1<E extends Class1<E, B>, B extends Class1.Class2<E, B>> {
abstract class Class2<E extends Class1<E, B>, B extends Class2<E, B>> {}
}

class Class3 {
private void f(Class1<?, ?> x) {}
}
}

0 comments on commit 42ceca4

Please sign in to comment.