-
Notifications
You must be signed in to change notification settings - Fork 5.8k
8278078: Cannot reference super before supertype constructor has been called #6642
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
👋 Welcome back asotona! A progress list of the required criteria for merging this PR into |
Webrevs
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. For a qualified super
call there are basically two cases:
- qualifier is an interface name
- qualifier is a class name
And there are three possible contexts:
a. constructors (this/super calls)
b. static
c. non-static
(in the JLS, (a) and (b) are the same, but javac deals with them differently).
Now, javac was correct with { b, c } x ( 1, 2 }, even before the problematic patch. It was also correct with (a, 2). But in the case of (a, 1) javac accepted the code even if that was, essentially, a reference to this
before super
.
The patch in 8261006 fixes this, but, while now javac rejects (a, 1), it also ends up rejecting (a, 2), which is a mistake.
Your patch seems to introduce a sharper distinction between handling of (1) and (2), so it looks good.
But I suggest that we test all possible combinations of { a, b, c } x { 1, 2 } - where for (a) we try both with super() and this() calls.
yep the patch looks very sensible, modulo the tests proposed by Maurizio which will complete it |
I'm actually not quite sure what the b. static and c. non-static contexts exactly mean in a context of this issue and how is it related with the bug subject "cannot reference super before supertype constructor has been called". This only specifically failing case (constructor with super call to enclosing class) has been identified from the large regression compilation Corpus experiment. I would prefer to track improvements in the actual test coverage as a separate issue, mainly to don't block this specific quick regression fix and have more time to design the test matrix more precisely. Thanks, |
It's ok to add more tests later. But at the very least I would like to see now a test which tries also
|
extended set of compilation validation tests added set of negative tests that should result in compilation error
test/langtools/tools/javac/8278078/ValidThisAndSuperInConstructorArgTest.java
Outdated
Show resolved
Hide resolved
test/langtools/tools/javac/8278078/InvalidThisAndSuperInConstructorArgTest.java
Show resolved
Hide resolved
@asotona This change now passes all automated pre-integration checks. ℹ️ This project also has non-automated pre-integration requirements. Please see the file CONTRIBUTING.md for details. After integration, the commit message for the final commit will be:
You can use pull request commands such as /summary, /contributor and /issue to adjust it as needed. At the time when this comment was updated there had been 18 new commits pushed to the
As there are no conflicts, your changes will automatically be rebased on top of these commits when integrating. If you prefer to avoid this automatic rebasing, please check the documentation for the /integrate command for further details. ➡️ To integrate this PR with the above commit message to the |
@@ -4348,7 +4348,8 @@ public void visitSelect(JCFieldAccess tree) { | |||
if (env.info.isSelfCall && | |||
((sym.name == names._this && | |||
site.tsym == env.enclClass.sym) || | |||
sym.name == names._super && env.info.constructorArgs)) { | |||
sym.name == names._super && env.info.constructorArgs && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe for later - let's refactor this to:
if (sym.name == names._this) {
if (site.tsym == env.enclClass.sym) {
// error
}
} else if (sym.name == names._super && env.info.constructorArgs) {
if (sitesym.isInterface() || site.tsym == env.enclClass.sym) {
// error
}
}
The isSelfCall
should imply that env.info.constructorArgs
is true, probably no need to check twice.
/integrate |
Going to push as commit 8d9cb2e.
Your commit was automatically rebased without conflicts. |
Pull request #4376 (with fix of 8261006: 'super' qualified method references cannot occur in a static context) regressed compilation of all inner classes using .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:
This patch keeps throwing "cannot reference super" error for calls of .super and permits calls of .super
Plus it adds a new test.
Thanks,
Adam
Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk pull/6642/head:pull/6642
$ git checkout pull/6642
Update a local copy of the PR:
$ git checkout pull/6642
$ git pull https://git.openjdk.java.net/jdk pull/6642/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 6642
View PR using the GUI difftool:
$ git pr show -t 6642
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk/pull/6642.diff