Skip to content
This repository was archived by the owner on Sep 19, 2023. It is now read-only.
/ jdk20u Public archive

8302202: Incorrect desugaring of null-allowed nested patterns #7

Closed
wants to merge 1 commit into from

Conversation

lahodaj
Copy link
Contributor

@lahodaj lahodaj commented Feb 20, 2023

Original PR:
openjdk/jdk#12572

Original PR description:
Considering code like:

    private String test1b(Object i) {
        return switch (i) {
            case R1(Object o) when o == null -> "R1(null)";
            case R1(Object o) -> "R1(!null)";
            default -> "default";
        };
    }

javac will try to factor-out the common prefix, i.e. R1, and produce something along these lines:

        switch (i) {
            case R1 $r:
                Object c = $r.c();
                switch (c) {
                    case Object o when o == null: yield "R1(null)";
                    case Object o: yield "R1(!null)";
                }
            default -> "default";
        };

The problem with this code is that both cases in the nested switch must match null, but the bootstrap protocol only allows one case to match null (the SwitchBootstraps.typeSwitch method will return -1 for null). So this translation is broken, and will not match the first case if the component is null.

There are multiple ways to solve this problem, but the proposal here is change the way we accumulate the cases from which we factor out the common prefix, by stopping the accumulation after the first nullable case.

Another related issue is that when factoring out the common prefix, if the last case in the nested switch is has an unconditional pattern, but also has a guard, we need to generate a default to continue properly in the outer switch. Currently, the default is not generated when there's an unconditional pattern in the case, despite having a guard, and hence the case as a whole is not unconditional.


Progress

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

Issue

  • JDK-8302202: Incorrect desugaring of null-allowed nested patterns

Reviewing

Using git

Checkout this PR locally:
$ git fetch https://git.openjdk.org/jdk20u pull/7/head:pull/7
$ git checkout pull/7

Update a local copy of the PR:
$ git checkout pull/7
$ git pull https://git.openjdk.org/jdk20u pull/7/head

Using Skara CLI tools

Checkout this PR locally:
$ git pr checkout 7

View PR using the GUI difftool:
$ git pr show -t 7

Using diff file

Download this PR as a diff file:
https://git.openjdk.org/jdk20u/pull/7.diff

@bridgekeeper
Copy link

bridgekeeper bot commented Feb 20, 2023

👋 Welcome back jlahoda! 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 changed the title Backport dc55a7fc877ab5ea4efbed90454194008143aeb4 8302202: Incorrect desugaring of null-allowed nested patterns Feb 20, 2023
@openjdk
Copy link

openjdk bot commented Feb 20, 2023

This backport pull request has now been updated with issue from the original commit.

@openjdk
Copy link

openjdk bot commented Feb 20, 2023

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

8302202: Incorrect desugaring of null-allowed nested patterns

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 no new commits pushed to the master branch. If another commit should be pushed before you perform the /integrate command, your PR will be automatically rebased. If you prefer to avoid any potential 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 ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 20, 2023
@mlbridge
Copy link

mlbridge bot commented Feb 20, 2023

Webrevs

@lahodaj
Copy link
Contributor Author

lahodaj commented Feb 27, 2023

/integrate

@openjdk
Copy link

openjdk bot commented Feb 27, 2023

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

  • cc33209: 8301858: Verification error when compiling switch with record patterns
  • a7d4a1a: 8295951: intermittent cmp_baseline task failures with CDS files
  • c6a25f4: 8302879: doc/building.md update link to jtreg builds

Your commit was automatically rebased without conflicts.

@openjdk openjdk bot added the integrated Pull request has been integrated label Feb 27, 2023
@openjdk openjdk bot closed this Feb 27, 2023
@openjdk openjdk bot removed ready Pull request is ready to be integrated rfr Pull request is ready for review labels Feb 27, 2023
@openjdk
Copy link

openjdk bot commented Feb 27, 2023

@lahodaj Pushed as commit db260e5.

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

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
backport clean integrated Pull request has been integrated
Development

Successfully merging this pull request may close these issues.

1 participant