RFR: 8334248: Invalid error for early construction local class constructor method reference [v2]
Archie Cobbs
acobbs at openjdk.org
Sat Jun 15 15:37:31 UTC 2024
On Fri, 14 Jun 2024 21:26:40 GMT, Maurizio Cimadamore <mcimadamore at openjdk.org> wrote:
> As far as I can tell, that additional check for method reference is there "only" to generate a better error message. And, in fact, the check in Resolve dominates the one in Attr: even if the check you tweaked in this PR is commented out completely, no regression test fails.
That may have been true before "flexible constructors", but it's not now - when that check is commented out, this program compiles successfully for me (erroneously), leading to a verifier error:
class Q {
class Inner { }
public Q() {
this(Inner::new);
}
public Q(Runnable r) {
}
public static void main(String[] args) {
new Q();
}
}
> Ideally we should only keep the check in Resolve (as that generates a better error), but augment it so that it detects the issue described in 8173456.
I agree that the remaining problem seems to be within `Resolve.resolveImplicitThis()`.
See commit e0f5d183651 to this PR where I tried to fix it... I'm curious if it that change looks correct to you?
In any case, when that commit is combined with all the other patches floating around (yours & mine), all of the `langtools_javac` regression tests (including the test for JDK-8173456) are passing, and the `Q.java` example above now correctly yields:
Q.java:4: error: cannot reference this before supertype constructor has been called
this(Inner::new);
^
1 error
-------------
PR Comment: https://git.openjdk.org/jdk/pull/19705#issuecomment-2169920987
More information about the compiler-dev
mailing list