-
Notifications
You must be signed in to change notification settings - Fork 5.8k
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
8282274: Compiler implementation for Pattern Matching for switch (Third Preview) #8182
Closed
+684
−455
Closed
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
b47f6c0
Moving guards to switches.
lahodaj 2f02c93
Moving guards to cases.
lahodaj e92ca08
Updating null handling.
lahodaj 78a3fb2
Merge branch 'case-guard' into type-patterns-third
lahodaj 5e0f558
Merge branch 'switch-null' into type-patterns-third
lahodaj 757924e
Adding MatchException.
lahodaj 66b4f01
Merge branch 'master' into type-patterns-third
lahodaj 5d55161
Guards should be a property of (pattern) case labels, not cases.
lahodaj 8c1b413
Merge branch 'master' into type-patterns-third
lahodaj 3eba02a
Cleanup
lahodaj da8401d
Adding a test for a NPE from guards.
lahodaj d7e2eb0
Fixing tests.
lahodaj ef7a7d6
Cleanup.
lahodaj 311d68a
Adjusting to review feedback.
lahodaj dc00154
Cleanup - more total -> unconditional pattern renaming.
lahodaj 76f2d05
Cleanup, fixing tests.
lahodaj 2e27be0
Merge branch 'master' into type-patterns-third
lahodaj 9f290cd
Reference-type pattern is not applicable at a selector of a primitive…
lahodaj a4ac056
Merge branch 'master' into type-patterns-third
lahodaj 115605a
Reducing MatchException constructors.
lahodaj cb5c1d2
Merge branch 'master' into type-patterns-third
lahodaj 1101ad4
Merge branch 'master' into type-patterns-third
lahodaj 9fe0a1d
Case label elements cannot be unguarded if they have a guard of a typ…
lahodaj b0fb8dc
Updating naming to more closely follow the spec: total patterns are r…
lahodaj e903084
Cleanup as suggested on the PR review.
lahodaj 2299195
Fixing test - restoring accidentally removed condition.
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
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
|
@@ -174,8 +174,8 @@ protected Attr(Context context) { | |
allowRecords = Feature.RECORDS.allowedInSource(source); | ||
allowPatternSwitch = (preview.isEnabled() || !preview.isPreview(Feature.PATTERN_SWITCH)) && | ||
Feature.PATTERN_SWITCH.allowedInSource(source); | ||
allowTotalPatternsInstance = (preview.isEnabled() || !preview.isPreview(Feature.TOTAL_PATTERN_IN_INSTACEOF)) && | ||
Feature.TOTAL_PATTERN_IN_INSTACEOF.allowedInSource(source); | ||
allowUnconditionalPatternsInstance = (preview.isEnabled() || !preview.isPreview(Feature.UNCONDITIONAL_PATTERN_IN_INSTANCEOF)) && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: perhaps adding "Of" to this already long variable name doesn't add much in terms of chars, but makes the meaning of the variable name clearer? |
||
Feature.UNCONDITIONAL_PATTERN_IN_INSTANCEOF.allowedInSource(source); | ||
sourceName = source.name; | ||
useBeforeDeclarationWarning = options.isSet("useBeforeDeclarationWarning"); | ||
|
||
|
@@ -222,7 +222,7 @@ protected Attr(Context context) { | |
|
||
/** Are total patterns in instanceof allowed | ||
*/ | ||
private final boolean allowTotalPatternsInstance; | ||
private final boolean allowUnconditionalPatternsInstance; | ||
|
||
/** | ||
* Switch: warn about use of variable before declaration? | ||
|
@@ -1794,7 +1794,7 @@ private void handleSwitch(JCTree switchTree, | |
} | ||
matchBindings = matchBindingsComputer.caseGuard(c, afterPattern, matchBindings); | ||
} | ||
boolean unconditional = TreeInfo.unconditionalCaseLabel(pat); | ||
boolean unconditional = TreeInfo.unrefinedCaseLabel(pat); | ||
boolean isTotal = unconditional && | ||
!patternType.isErroneous() && | ||
types.isSubtype(types.erasure(seltype), patternType); | ||
|
@@ -4109,10 +4109,10 @@ public void visitTypeTest(JCInstanceOf tree) { | |
clazztype = tree.pattern.type; | ||
if (types.isSubtype(exprtype, clazztype) && | ||
!exprtype.isErroneous() && !clazztype.isErroneous()) { | ||
if (!allowTotalPatternsInstance) { | ||
if (!allowUnconditionalPatternsInstance) { | ||
log.error(tree.pos(), Errors.InstanceofPatternNoSubtype(exprtype, clazztype)); | ||
} else if (preview.isPreview(Feature.TOTAL_PATTERN_IN_INSTACEOF)) { | ||
preview.warnPreview(tree.pattern.pos(), Feature.TOTAL_PATTERN_IN_INSTACEOF); | ||
} else if (preview.isPreview(Feature.UNCONDITIONAL_PATTERN_IN_INSTANCEOF)) { | ||
preview.warnPreview(tree.pattern.pos(), Feature.UNCONDITIONAL_PATTERN_IN_INSTANCEOF); | ||
} | ||
} | ||
typeTree = TreeInfo.primaryPatternTree((JCPattern) tree.pattern).var.vartype; | ||
|
This file contains 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 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
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.
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 looks odd - it seems like the sentence is like this:
the cause ( foo ). (bar)
. E.g. the test in parenthesis exceeds the test outside parenthesis by a wide margin. I suggest both here and in the "message" @param to avoid the parenthesis and split the sentence instead. Examples:and
Of course this is just an idea.
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.
I believe this text is taken form another exception in java.lang. If that would be OK, I'd look at this in a followup/separate issue.
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.
ok!