Skip to content
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

8278078: Cannot reference super before supertype constructor has been called #6642

Closed
wants to merge 4 commits into from

Conversation

asotona
Copy link
Member

@asotona asotona commented Dec 1, 2021

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:

    class EnclClass { 
        class InnerClass extends Exception { 
            InnerClass() { 
                super(EnclClass.super.toString()); 
            } 
        } 
    } 

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

  • Change must not contain extraneous whitespace
  • Commit message must refer to an issue
  • Change must be properly reviewed

Issue

  • JDK-8278078: Cannot reference super before supertype constructor has been called

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

@bridgekeeper
Copy link

@bridgekeeper bridgekeeper bot commented Dec 1, 2021

👋 Welcome back asotona! A progress list of the required criteria for merging this PR into master will be added to the body of your pull request. There are additional pull request commands available for use with this pull request.

@openjdk openjdk bot added the rfr label Dec 1, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Dec 1, 2021

@asotona The following label will be automatically applied to this pull request:

  • compiler

When this pull request is ready to be reviewed, an "RFR" email will be sent to the corresponding mailing list. If you would like to change these labels, use the /label pull request command.

@openjdk openjdk bot added the compiler label Dec 1, 2021
@mlbridge
Copy link

@mlbridge mlbridge bot commented Dec 1, 2021

Copy link
Contributor

@mcimadamore mcimadamore left a comment

Looks good. For a qualified super call there are basically two cases:

  1. qualifier is an interface name
  2. 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.

@vicente-romero-oracle
Copy link
Contributor

@vicente-romero-oracle vicente-romero-oracle commented Dec 1, 2021

yep the patch looks very sensible, modulo the tests proposed by Maurizio which will complete it

@asotona
Copy link
Member Author

@asotona asotona commented Dec 1, 2021

And there are three possible contexts:

a. constructors (this/super calls)
b. static
c. non-static

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,
Adam

@mcimadamore
Copy link
Contributor

@mcimadamore mcimadamore commented Dec 1, 2021

And there are three possible contexts:
a. constructors (this/super calls)
b. static
c. non-static

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.

It's ok to add more tests later. But at the very least I would like to see now a test which tries also this(Foo.super.m()) - because the two forms are very related.

Thanks, Adam

extended set of compilation validation tests
added set of negative tests that should result in compilation error
@asotona asotona changed the title 8278078: cannot reference super before supertype constructor has been called 8278078: error: cannot reference super before supertype constructor has been called Dec 2, 2021
@asotona asotona changed the title 8278078: error: cannot reference super before supertype constructor has been called 8278078: Cannot reference super before supertype constructor has been called Dec 2, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Dec 2, 2021

@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:

8278078: Cannot reference super before supertype constructor has been called

Reviewed-by: mcimadamore

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 master branch:

  • b79554b: 8278130: Failure in jdk/javadoc/tool/CheckManPageOptions.java after JDK-8274639
  • ea905bd: 8277924: Small tweaks to foreign function and memory API
  • e002bfe: 8278049: G1: add precondition to set_remainder_to_point_to_start
  • 16cfbc4: 8278071: typos in MemorySegment::set, MemorySegment::setAtIndex javadoc
  • 84ca14d: 8277194: applications/runthese/RunThese30M.java crashes with jfrSymbolTable.cpp:305 assert(_instance != null)
  • 103da8f: 8274639: Provide a way to disable warnings for cross-modular links
  • 088b244: 8251216: Implement MD5 intrinsics on AArch64
  • a093cdd: 8276657: XSLT compiler tries to define a class with empty name
  • 8198807: 8266435: WBMPImageReader.read() should not truncate the input stream
  • b226ab9: 8276141: XPathFactory set/getProperty method
  • ... and 8 more: https://git.openjdk.java.net/jdk/compare/abaa073bcbdb202658c8a97401ffb098d71e0f16...master

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 master branch, type /integrate in a new comment.

@openjdk openjdk bot added the ready label Dec 2, 2021
@@ -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 &&
Copy link
Contributor

@mcimadamore mcimadamore Dec 2, 2021

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.

@asotona
Copy link
Member Author

@asotona asotona commented Dec 2, 2021

/integrate

@openjdk
Copy link

@openjdk openjdk bot commented Dec 2, 2021

Going to push as commit 8d9cb2e.
Since your change was applied there have been 23 commits pushed to the master branch:

  • 65960f7: 8277753: Long*VectorTests.java fail with "bad AD file" on x86_32 after JDK-8276162
  • 3889af3: 8277906: Incorrect type for IV phi of long counted loops after CCP
  • d2b16c8: 8276126: Dump time class transformation causes heap objects of non-boot classes to be archived
  • 7696897: 8276837: [macos]: Error when signing the additional launcher
  • 3d98ec1: 8273056: java.util.random does not correctly sample exponential or Gaussian distributions
  • b79554b: 8278130: Failure in jdk/javadoc/tool/CheckManPageOptions.java after JDK-8274639
  • ea905bd: 8277924: Small tweaks to foreign function and memory API
  • e002bfe: 8278049: G1: add precondition to set_remainder_to_point_to_start
  • 16cfbc4: 8278071: typos in MemorySegment::set, MemorySegment::setAtIndex javadoc
  • 84ca14d: 8277194: applications/runthese/RunThese30M.java crashes with jfrSymbolTable.cpp:305 assert(_instance != null)
  • ... and 13 more: https://git.openjdk.java.net/jdk/compare/abaa073bcbdb202658c8a97401ffb098d71e0f16...master

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot closed this Dec 2, 2021
@openjdk openjdk bot added integrated and removed ready rfr labels Dec 2, 2021
@openjdk
Copy link

@openjdk openjdk bot commented Dec 2, 2021

@asotona Pushed as commit 8d9cb2e.

💡 You may see a message that your pull request was closed with unmerged commits. This can be safely ignored.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler integrated
3 participants