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

Some captured types are from a previous capture. #4882

Merged
merged 1 commit 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 @@ -570,7 +570,8 @@ protected Void visitParameterizedType(AnnotatedDeclaredType type, ParameterizedT
Map<TypeVariable, AnnotatedTypeMirror> typeVarToWildcard = new HashMap<>(numTypeArgs);
for (int i = 0; i < numTypeArgs; i++) {
AnnotatedTypeMirror captureTypeArg = capturedType.getTypeArguments().get(i);
if (TypesUtils.isCapturedTypeVariable(captureTypeArg.getUnderlyingType())) {
if (TypesUtils.isCapturedTypeVariable(captureTypeArg.getUnderlyingType())
&& type.getTypeArguments().get(i).getKind() == TypeKind.WILDCARD) {
AnnotatedTypeVariable capturedTypeVar = (AnnotatedTypeVariable) captureTypeArg;
AnnotatedWildcardType wildcard = (AnnotatedWildcardType) type.getTypeArguments().get(i);
typeVarToWildcard.put(capturedTypeVar.getUnderlyingType(), wildcard);
Expand All @@ -579,7 +580,8 @@ protected Void visitParameterizedType(AnnotatedDeclaredType type, ParameterizedT

for (int i = 0; i < numTypeArgs; i++) {
AnnotatedTypeMirror captureTypeArg = capturedType.getTypeArguments().get(i);
if (TypesUtils.isCapturedTypeVariable(captureTypeArg.getUnderlyingType())) {
if (TypesUtils.isCapturedTypeVariable(captureTypeArg.getUnderlyingType())
&& type.getTypeArguments().get(i).getKind() == TypeKind.WILDCARD) {
AnnotatedTypeVariable capturedTypeVar = (AnnotatedTypeVariable) captureTypeArg;
AnnotatedWildcardType wildcard = (AnnotatedWildcardType) type.getTypeArguments().get(i);
// Substitute the captured type variables with their wildcards. Without this, the
Expand Down
13 changes: 13 additions & 0 deletions framework/tests/all-systems/Issue4878.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import java.util.List;

class Issue4878 {
<Q> void f(S4878<?> s, Q v) {
s.p().forEach(param -> {});
}
}

class A4878<L, E> {}

abstract class S4878<T> {
abstract List<A4878<T, ?>> p();
}
25 changes: 25 additions & 0 deletions framework/tests/all-systems/Issue4878Orig.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import java.util.List;

interface M4878Orig {}

class A4878Orig<T extends M4878Orig, F> {
void p(T v) {}
}

abstract class S<T extends M4878Orig> {
abstract List<A4878Orig<T, ?>> p();
}

class Issue4878Orig {

@SuppressWarnings("unchecked")
<T extends M4878Orig> void f(S<?> s, T v) {
s.p()
.forEach(
field -> {
Object o = field;
A4878Orig<T, ?> typedField = (A4878Orig<T, ?>) field;
typedField.p(v);
});
}
}