Skip to content

Commit

Permalink
[21] Fixing the synthetic default instrumentation stack verify error (e…
Browse files Browse the repository at this point in the history
  • Loading branch information
mpalat authored Jul 18, 2023
1 parent bbef232 commit 4211dd4
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
*
* SPDX-License-Identifier: EPL-2.0
*
* This is an implementation of an early-draft specification developed under the Java
* Community Process (JCP) and is made available for testing and evaluation purposes
* only. The code is not compatible with any specification of the JCP.
*
* Contributors:
* IBM Corporation - initial API and implementation
* Stephan Herrmann - Contributions for
Expand Down Expand Up @@ -626,7 +630,16 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {
&& this.expression.resolvedType instanceof ReferenceBinding
&& ((ReferenceBinding) this.expression.resolvedType).isSealed();

if (isEnumSwitchWithoutDefaultCase || isPatternSwitchSealedWithoutDefaultCase) {
boolean isRecordPatternSwitchWithoutDefault = this.defaultCase == null
&& compilerOptions != null
&& this.containsPatterns
&& JavaFeature.RECORD_PATTERNS.isSupported(compilerOptions)
&& JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(compilerOptions)
&& this.expression.resolvedType instanceof ReferenceBinding
&& this.expression.resolvedType.isRecord();
if (isEnumSwitchWithoutDefaultCase
|| isPatternSwitchSealedWithoutDefaultCase
|| isRecordPatternSwitchWithoutDefault) {
// we want to force an line number entry to get an end position after the switch statement
if (this.preSwitchInitStateIndex != -1) {
codeStream.removeNotDefinitelyAssignedVariables(currentScope, this.preSwitchInitStateIndex);
Expand Down Expand Up @@ -665,7 +678,9 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) {
}
// place the trailing labels (for break and default case)
this.breakLabel.place();
if (this.defaultCase == null && !(enumInSwitchExpression || isPatternSwitchSealedWithoutDefaultCase)) {
if (this.defaultCase == null && !(enumInSwitchExpression
|| isPatternSwitchSealedWithoutDefaultCase
|| isRecordPatternSwitchWithoutDefault)) {
// we want to force an line number entry to get an end position after the switch statement
codeStream.recordPositionsFrom(codeStream.position, this.sourceEnd, true);
defaultLabel.place();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2884,7 +2884,7 @@ public void testIssue1224_7() {
}
// Fails with VerifyError since we allow the switch now but don't
// generate a label/action for implicit default.
public void _testIssue1224_8() {
public void testIssue1224_8() {
runConformTest(new String[] {
"X.java",
"record Record(int a) {}\n"
Expand Down

0 comments on commit 4211dd4

Please sign in to comment.