Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct capture type variable method. #4875

Merged
merged 3 commits into from
Aug 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {}
}
}