RFR: 8261006: 'super' qualified method references cannot occur in a static context [v2]

Vicente Romero vromero at openjdk.java.net
Fri Jun 25 17:08:39 UTC 2021


> 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 with a new target base due to a merge or a rebase. The incremental webrev excludes the unrelated changes brought in by the merge/rebase. The pull request contains two additional commits since the last revision:

 - Merge branch 'master' into JDK-8261006
 - 8261006: fail to parse broken interface::method in lambda

-------------

Changes:
  - all: https://git.openjdk.java.net/jdk/pull/4376/files
  - new: https://git.openjdk.java.net/jdk/pull/4376/files/f320647e..7dfe9271

Webrevs:
 - full: https://webrevs.openjdk.java.net/?repo=jdk&pr=4376&range=01
 - incr: https://webrevs.openjdk.java.net/?repo=jdk&pr=4376&range=00-01

  Stats: 508480 lines in 1645 files changed: 478594 ins; 23029 del; 6857 mod
  Patch: https://git.openjdk.java.net/jdk/pull/4376.diff
  Fetch: git fetch https://git.openjdk.java.net/jdk pull/4376/head:pull/4376

PR: https://git.openjdk.java.net/jdk/pull/4376


More information about the compiler-dev mailing list