RFR: 8278078: cannot reference super before supertype constructor has been called [v2]
Maurizio Cimadamore
mcimadamore at openjdk.java.net
Wed Dec 1 21:30:36 UTC 2021
On Wed, 1 Dec 2021 20:35:09 GMT, Adam Sotona <asotona at openjdk.org> wrote:
>> Pull request #4376 (with fix of 8261006: 'super' qualified method references cannot occur in a static context) regressed compilation of all inner classes using <enclosing class>.super pattern in their constructor argument to fail with:
>> error: cannot reference super before supertype constructor has been called
>>
>> For example following source fragment cannot be compiled since that:
>>
>> class EnclClass {
>> class InnerClass extends Exception {
>> InnerClass() {
>> super(EnclClass.super.toString());
>> }
>> }
>> }
>>
>>
>> This patch keeps throwing "cannot reference super" error for calls of <interface>.super and permits calls of <enclosing class>.super
>>
>> Plus it adds a new test.
>>
>> Thanks,
>> Adam
>
> Adam Sotona has updated the pull request incrementally with one additional commit since the last revision:
>
> fixed typo in test name
test/langtools/tools/javac/8278078/EnclosingSuperTest.java line 7:
> 5: * @run compile EclosingSuperTest.java
> 6: */
> 7: public class EnclosingSuperTest {
My suggestion for another test is something like this:
public class EnclosingSuperTest2 {
class InnerClass extends Exception {
InnerClass() {
this(EnclosingSuperTest2.super.toString());
}
InnerClass(String s) { }
}
}
This test also pass before the problematic fix, and fails afterwards, so I think we should add it too.
-------------
PR: https://git.openjdk.java.net/jdk/pull/6642
More information about the compiler-dev
mailing list