RFR: 8261006: 'super' qualified method references cannot occur in a static context [v4]
Srikanth Adayapalam
sadayapalam at openjdk.java.net
Mon Jun 28 11:17:03 UTC 2021
On Sat, 26 Jun 2021 02:23:26 GMT, Vicente Romero <vromero at openjdk.org> wrote:
>> Please review this PR, currently javac is accepting code like:
>>
>>
>> import java.util.function.Supplier;
>>
>> public class MethodReferenceInConstructorInvocation {
>> interface Bar {
>> default String getString() { return ""; }
>> }
>>
>> static class Foo implements Bar {
>> public Foo() { this(Bar.super::getString); }
>> public Foo(Supplier<String> sString) {}
>> }
>> }
>>
>>
>> but the spec states in `15.13 Method Reference Expressions`:
>>
>> If a method reference expression has the form super :: [TypeArguments] Identifier
>> or TypeName . super :: [TypeArguments] Identifier, it is a compile-time error if
>> the expression occurs in a static context (§8.1.3).
>>
>> and a constructor invocation is a static context. So method references of this form, qualified by `super`, should be rejected by the compiler if they appear in a static context.
>>
>> TIA
>
> Vicente Romero has updated the pull request incrementally with one additional commit since the last revision:
>
> updating comment
Marked as reviewed by sadayapalam (Reviewer).
The diags/examples test is redundant I think since we already have CantRefBeforeConstr.java there and it is a duplicate of lambda/MethodReferenceInConstructorInvocation
With the minor nits in tests addressed and additional test added, this patch looks good to go!
test/langtools/tools/javac/diags/examples/MethodReferenceNotAllowedStaticContext.java line 44:
> 42: }
> 43: }
> 44: }
I think this test is redundant
test/langtools/tools/javac/lambda/methodReference/MethodReferenceInConstructorInvocation.java line 4:
> 2: * @test /nodynamiccopyright/
> 3: * @bug 8261006
> 4: * @summary fail to parse broken interface::method in lambda
The summary looks copy pasted ?? Sorry didn't catch earlier.
-------------
PR: https://git.openjdk.java.net/jdk/pull/4376
More information about the compiler-dev
mailing list