Skip to content
Open
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 @@ -675,6 +675,7 @@ public void resolveReceiver() {
this.receiver.qualifyingName = null;
}

resolvedReceiverType = this.scope.environment().getShallowUnannotatedType(resolvedReceiverType);
if (TypeBinding.notEquals(enclosingReceiver, resolvedReceiverType)) {
this.scope.problemReporter().illegalTypeForExplicitThis(this.receiver, enclosingReceiver);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2451,6 +2451,19 @@ public void addResolutionListener(IQualifiedTypeResolutionListener resolutionLis
public TypeBinding getUnannotatedType(TypeBinding typeBinding) {
return this.typeSystem.getUnannotatedType(typeBinding);
}
public TypeBinding getShallowUnannotatedType(TypeBinding typeBinding) {
if (typeBinding instanceof ReferenceBinding ref && ref.hasTypeAnnotations()) {
TypeBinding original = ref.original();
if (ref instanceof ParameterizedTypeBinding ptb && ptb.arguments != null && original instanceof ReferenceBinding originalRef) {
for (TypeBinding arg : ptb.arguments) {
if (arg.hasTypeAnnotations())
return createParameterizedType(originalRef, ptb.arguments, ptb.enclosingType);
}
}
return this.typeSystem.getUnannotatedType(typeBinding);
}
return typeBinding;
}

// Given a type, return all its variously annotated versions.
public TypeBinding[] getAnnotatedTypes(TypeBinding type) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19812,4 +19812,27 @@ void expire() {}
""";
runner.runNegativeTest();
}

public void testGH4494() throws Exception {
runConformTest(new String[] {
"AnnotatedExplicitReceiverError.java",
"""
import java.lang.annotation.ElementType;
import java.lang.annotation.Target;

public class AnnotatedExplicitReceiverError {
@Target({ ElementType.TYPE_USE})
private static @interface A { }

@Target({ ElementType.TYPE_USE, ElementType.TYPE_PARAMETER })
private static @interface F { }

static class P<@A T> {
public void explicitReceiver(@F P<T> this) { // error here
}
}
}
"""
});
}
}
Loading