Skip to content
Merged
20 changes: 20 additions & 0 deletions checker/jtreg/nullness/MethodReceiverTypeErrorMessageTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* @test
* @summary Test case for method receiver type in error message. If it is a non-raw type, it should be printed as such.
*
* @compile/fail/ref=MethodReceiverTypeErrorMessageTest.out -XDrawDiagnostics -processor org.checkerframework.checker.nullness.NullnessChecker MethodReceiverTypeErrorMessageTest.java
*/
public class MethodReceiverTypeErrorMessageTest<T> {

MethodReceiverTypeErrorMessageTest() {
foo();
}

void foo() {}

static class StringSpecialization extends MethodReceiverTypeErrorMessageTest<String> {
StringSpecialization() {
foo();
}
}
}
7 changes: 7 additions & 0 deletions checker/jtreg/nullness/MethodReceiverTypeErrorMessageTest.out
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
MethodReceiverTypeErrorMessageTest.java:10:12: compiler.err.proc.messager: [method.invocation.invalid] call to foo() not allowed on the given receiver.
found : @UnderInitialization(MethodReceiverTypeErrorMessageTest.class) MethodReceiverTypeErrorMessageTest<T extends @Initialized Object>
required: @Initialized MethodReceiverTypeErrorMessageTest<T extends @Initialized Object>
MethodReceiverTypeErrorMessageTest.java:17:16: compiler.err.proc.messager: [method.invocation.invalid] call to foo() not allowed on the given receiver.
found : @UnderInitialization(MethodReceiverTypeErrorMessageTest.StringSpecialization.class) StringSpecialization
required: @Initialized MethodReceiverTypeErrorMessageTest<@Initialized String>
2 errors
Original file line number Diff line number Diff line change
Expand Up @@ -3992,10 +3992,11 @@ protected void checkMethodInvocability(
if (!skipReceiverSubtypeCheck(tree, erasedMethodReceiver, treeReceiver)) {
// The diagnostic can be a bit misleading because the check is of the receiver but
// `tree` is the entire method invocation (where the receiver might be implicit).
commonAssignmentCheckStartDiagnostic(erasedMethodReceiver, erasedTreeReceiver, tree);
commonAssignmentCheckStartDiagnostic(
method.getReceiverType(), erasedTreeReceiver, tree);
boolean success = typeHierarchy.isSubtype(erasedTreeReceiver, erasedMethodReceiver);
commonAssignmentCheckEndDiagnostic(
success, null, erasedMethodReceiver, erasedTreeReceiver, tree);
success, null, method.getReceiverType(), erasedTreeReceiver, tree);
if (!success) {
// Don't report the erased types because they show up with '</*RAW*/>' as type args.
Comment thread
aosen-xiong marked this conversation as resolved.
reportMethodInvocabilityError(tree, treeReceiver, method.getReceiverType());
Expand Down
Loading