-
Notifications
You must be signed in to change notification settings - Fork 6.2k
8367530: The exhaustiveness errors could be improved #27256
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
Open
lahodaj
wants to merge
47
commits into
openjdk:master
Choose a base branch
from
lahodaj:JDK-8367530
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,408
−95
Open
Changes from all commits
Commits
Show all changes
47 commits
Select commit
Hold shift + click to select a range
3d6728c
A attempt to create more user-friendly errors for switch exaustiveness.
lahodaj cad665e
Improvements.
lahodaj 2cfbc71
8364991: Incorrect not-exhaustive error
lahodaj 36e337f
Merge branch 'JDK-8364991' into exhaustiveness-errors
lahodaj e4f655d
Improving test debuggability.
lahodaj 8647a74
Better name.
lahodaj 2f569e3
Merge branch 'JDK-8364991' into exhaustiveness-errors
lahodaj 5f70d8b
Avoid computing exhaustiveness unnecessarily, cleanup.
lahodaj 74c72e6
Merge branch 'master' into JDK-8364991
lahodaj 8735a3d
Adjusting to spec.
lahodaj 7320a5a
Merge branch 'JDK-8364991' into exhaustiveness-errors
lahodaj 29428b3
Fixing the exhaustiveness search.
lahodaj bed37c4
Adding test.
lahodaj 0d77887
8367499: Refactor exhaustiveness computation from Flow into a separat…
lahodaj 6963835
Adding doc comment.
lahodaj d54e53d
Merge branch 'JDK-8367499' into JDK-8367530
lahodaj 31d3990
Cleanup, making timeout work.
lahodaj ce83803
Enabling disabled test.
lahodaj 0ee6086
Simplifying the code as suggested.
lahodaj c78f696
Cleanup.
lahodaj 9066c51
Cleanup.
lahodaj 789f09e
Cleanup.
lahodaj 78af109
Fixing tests.
lahodaj e69c20e
Merge branch 'JDK-8364991' into JDK-8367499
lahodaj d35773c
Merge branch 'JDK-8367499' into JDK-8367530
lahodaj 38089d1
Better visualisation.
lahodaj 026dc4c
Adding tests with generic records.
lahodaj 9138ef6
Factoring out the 'substitutable' check, as suggested.
lahodaj 51b7fc2
Adding explanation to the replaces map.
lahodaj 11ee4df
Caching isSubtype, as suggested.
lahodaj 25d1b95
Avoiding the use of IdentityHashMap.
lahodaj 998e08c
8367499: Refactor exhaustiveness computation from Flow into a separat…
lahodaj 0290ecb
Merge branch 'JDK-8367499-2' into JDK-8364991
lahodaj dad7c56
Merge branch 'JDK-8364991-2' into JDK-8367530-2
lahodaj b79bce1
Fixing tests
lahodaj ba70f89
Merge branch 'master' into JDK-8364991
lahodaj e6a3f0d
Merge branch 'master' into JDK-8364991
lahodaj b7c3334
Merge branch 'JDK-8364991' into JDK-8367530
lahodaj 50ddab0
Reflecting review comments.
lahodaj 75c3cb0
Apply suggestions from code review
lahodaj 8c48cf8
Cleanup, reflecting review feedback.
lahodaj da13071
Fixing trailing whitespaces.
lahodaj 3e4af72
Merge branch 'master' into JDK-8367530
lahodaj 08fdb6d
Fixing cases that are based on review feedback.
lahodaj cee029c
Reflecting review feedback: using multi-line diagnostics; passing Pat…
lahodaj cfa2efa
Merge branch 'master' into JDK-8367530-3
lahodaj 1e6a018
Fixing test.
lahodaj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
716 changes: 639 additions & 77 deletions
716
src/jdk.compiler/share/classes/com/sun/tools/javac/comp/ExhaustivenessComputer.java
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
test/langtools/tools/javac/diags/examples/NotExhaustiveDetails.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| // key: compiler.err.not.exhaustive.details | ||
| // key: compiler.misc.not.exhaustive.detail | ||
| // options: -XDexhaustivityTimeout=-1 | ||
|
|
||
| class NotExhaustiveDetails { | ||
| int t(int i) { | ||
| return switch (i) { | ||
| case 0 -> -1; | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
test/langtools/tools/javac/diags/examples/NotExhaustiveStatementDetails.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| /* | ||
| * Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved. | ||
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
| * | ||
| * This code is free software; you can redistribute it and/or modify it | ||
| * under the terms of the GNU General Public License version 2 only, as | ||
| * published by the Free Software Foundation. | ||
| * | ||
| * This code is distributed in the hope that it will be useful, but WITHOUT | ||
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | ||
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | ||
| * version 2 for more details (a copy is included in the LICENSE file that | ||
| * accompanied this code). | ||
| * | ||
| * You should have received a copy of the GNU General Public License version | ||
| * 2 along with this work; if not, write to the Free Software Foundation, | ||
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. | ||
| * | ||
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA | ||
| * or visit www.oracle.com if you need additional information or have any | ||
| * questions. | ||
| */ | ||
|
|
||
| // key: compiler.err.not.exhaustive.statement.details | ||
| // key: compiler.misc.not.exhaustive.detail | ||
| // options: -XDexhaustivityTimeout=-1 | ||
|
|
||
| class NotExhaustiveDetails { | ||
| void t(Object o) { | ||
| switch (o) { | ||
| case String s -> System.err.println("String of length: " + s.length()); | ||
| }; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
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.
This
|=turned into=. Is that correct? I think so. Now it is guarded bytree.isExhaustiveitself right?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.
Yes, this is intentional. There is one more additional
if (!tree.isExhaustive)test below, which replaces the use of the or (but is faster in case we know the switch is exhaustive).