Integrated: 8270835: regression after JDK-8261006
Vicente Romero
vromero at openjdk.java.net
Tue Aug 17 20:51:30 UTC 2021
On Tue, 17 Aug 2021 16:57:26 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> This patch is fixing a regression introduced by the fix for [JDK-8261006](https://bugs.openjdk.java.net/browse/JDK-8261006), which was trying to fix a long standing bug in javac. These are the related sections in the spec:
>
>
> According to: 8.1.3 Inner Classes and Enclosing Instances:
>
> A construct (statement, local variable declaration statement, local class declaration,
> local interface declaration, or expression) occurs in a static context if the innermost:
> ...
> • explicit constructor invocation statement
>
> which encloses the construct is one of the following:
> • an explicit constructor invocation statement (§8.8.7.1)
> ...
> ...
> The purpose of a static context is to demarcate code that must not refer explicitly or
> implicitly to the current instance of the class whose declaration lexically encloses the static
> context. Consequently, code that occurs in a static context is restricted in the following
> ways:
> • Field accesses, method invocations, and method references may not be qualified by super (§15.11.2, §15.12.3, §15.13.1).
>
> also from: 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).
>
> Meaning that code like:
>
> this(Feature.super::getString); or
> this(Feature.super.getString());
>
> should be rejected by the compiler and it wasn't before the fix for [JDK-8261006](https://bugs.openjdk.java.net/browse/JDK-8261006). The regression was introduced because after [JDK-8261006](https://bugs.openjdk.java.net/browse/JDK-8261006) this code was rejected when it shouldn't:
>
> class A extends B {
> A(int i) {}
>
> class C extends B {
> class D extends S {
> D(float f) {
> C.super.ref.super(); // ok
> }
> }
> }
> }
>
> class B {
> B ref;
> class S {}
> }
>
> so it is OK to use `super` in the constructor's invocation qualifier but not in its arguments. So while processing the arguments or the qualifier of a constructor invocation, the compiler needs to know precisely what portion of the expression it is dealing with as different rules apply for the use of `this` or `super` in them. This is why this fix is adding a new flag to AttrContext to indicate if we are dealing with a constructor invocation argument or not.
>
> TIA
This pull request has now been integrated.
Changeset: 14623cde
Author: Vicente Romero <vromero at openjdk.org>
URL: https://git.openjdk.java.net/jdk/commit/14623cde3a20962e902043b556c5058ac208711f
Stats: 52 lines in 4 files changed: 51 ins; 0 del; 1 mod
8270835: regression after JDK-8261006
Reviewed-by: jlahoda
-------------
PR: https://git.openjdk.java.net/jdk/pull/5149
More information about the compiler-dev
mailing list