8268871: Adjust javac to updated exhaustiveness specification #78
Conversation
|
Webrevs
|
public void testExhaustiveIntersection(Path base) throws Exception { | ||
doTest(base, | ||
new String[]{""" | ||
package lib; |
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.
it will be nice to have additional tests with conditional patterns (total and not) to stress all the possible code paths
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.
Thanks Vicente! I've updated the patch based on your comments in a7a6169 .
What do you think?
Thanks!
} | ||
|
||
case TYP -> { | ||
for (Type sup : types.directSupertypes(sym.type)) { |
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.
just an observation, once a symbol has been processed, there is no need to process it again so you could keep a set of visited symbols to avoid visiting them again. Not a big deal performance wise unless we are switching on a sealed hierarchy with a lot of members I guess > 50 but we know what automatic code generators are capable of :)
@lahodaj This change now passes all automated pre-integration checks. 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 73 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.
|
/integrate |
Going to push as commit 4eb3212.
Your commit was automatically rebased without conflicts. |
The current updates spec for pattern matching in switch:
http://cr.openjdk.java.net/~gbierman/jep406/jep406-20210608/specs/patterns-switch-jls.html
tweaks the definition of exhaustive switches so that it include handling special types, like intersection types, sealed subclasses of sealed types, like:
etc. This patch attempts to tweak javac to work according to this specification. It builds covered types based on what types are covered, i.e. if all subtypes of a sealed type are covered, the sealed type itself is covered, and this is done transitively, so that in the example above,
D
andE
will markC
as covered, and thenB
andC
will markA
as covered, and as the type ifa
isA
, it means the switch is exhaustive.Progress
Issue
Reviewers
Reviewing
Using
git
Checkout this PR locally:
$ git fetch https://git.openjdk.java.net/jdk17 pull/78/head:pull/78
$ git checkout pull/78
Update a local copy of the PR:
$ git checkout pull/78
$ git pull https://git.openjdk.java.net/jdk17 pull/78/head
Using Skara CLI tools
Checkout this PR locally:
$ git pr checkout 78
View PR using the GUI difftool:
$ git pr show -t 78
Using diff file
Download this PR as a diff file:
https://git.openjdk.java.net/jdk17/pull/78.diff