From 5655c788b43349c41acd47767296e1465fc0e495 Mon Sep 17 00:00:00 2001 From: Srikanth Sankaran Date: Wed, 23 Oct 2024 07:28:13 +0530 Subject: [PATCH] Code review driven incremental cleanup of sealed types implementation --- .../internal/compiler/ast/CaseStatement.java | 2 + .../compiler/ast/SwitchExpression.java | 4 +- .../compiler/ast/SwitchStatement.java | 191 +++++++----------- .../internal/compiler/impl/JavaFeature.java | 2 +- .../compiler/lookup/ReferenceBinding.java | 7 +- .../internal/compiler/lookup/TypeBinding.java | 4 + .../compiler/lookup/TypeConstants.java | 1 + .../jdt/internal/compiler/parser/Parser.java | 1 - .../regression/PrimitiveInPatternsTestSH.java | 6 +- .../regression/RecordPatternTest.java | 20 +- .../regression/SwitchPatternTest.java | 1 - .../tests/compiler/regression/SwitchTest.java | 9 +- 12 files changed, 99 insertions(+), 149 deletions(-) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java index 3de3773e464..49fb1ecfaff 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/CaseStatement.java @@ -371,6 +371,8 @@ private Constant resolveCasePattern(BlockScope scope, TypeBinding caseType, Type if (type != null) { constant = IntConstant.fromValue(switchStatement.constantIndex); switchStatement.caseLabelElements.add(e); + if (e instanceof RecordPattern) + switchStatement.containsRecordPatterns = true; if (isUnguarded) switchStatement.caseLabelElementTypes.add(type); diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java index d31d16b2cb1..84545305744 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchExpression.java @@ -76,8 +76,8 @@ public ExpressionContext getExpressionContext() { return this.expressionContext; } @Override - protected boolean ignoreMissingDefaultCase(CompilerOptions compilerOptions, boolean isEnumSwitch) { - return isEnumSwitch; // mandatory error if not enum in switch expressions + protected boolean ignoreMissingDefaultCase(CompilerOptions compilerOptions) { + return true; } @Override protected void reportMissingEnumConstantCase(BlockScope upperScope, FieldBinding enumConstant) { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java index e33f7e345bf..b056f763969 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/ast/SwitchStatement.java @@ -87,6 +87,7 @@ public static record SingletonBootstrap(String id, char[] selector, char[] signa public int switchBits; public boolean containsPatterns; + public boolean containsRecordPatterns; public boolean containsNull; boolean nullProcessed = false; BranchLabel switchPatternRestartTarget; @@ -366,8 +367,7 @@ public boolean visit(TNode node) { } } if (node.type instanceof ReferenceBinding ref && ref.isSealed()) { - List allAllowedTypes = ref.getAllEnumerableReferenceTypes(); - this.covers &= caseElementsCoverSelectorType(allAllowedTypes, availableTypes); + this.covers &= caseElementsCoverSealedType(ref, availableTypes); return this.covers; } this.covers = false; @@ -824,13 +824,6 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) { int max = localKeysCopy[constantCount - 1]; int min = localKeysCopy[0]; if ((long) (constantCount * 2.5) > ((long) max - (long) min)) { - - // work-around 1.3 VM bug, if max>0x7FFF0000, must use lookup bytecode - // see http://dev.eclipse.org/bugs/show_bug.cgi?id=21557 - if (max > 0x7FFF0000 && currentScope.compilerOptions().complianceLevel < ClassFileConstants.JDK1_4) { - codeStream.lookupswitch(defaultLabel, this.constants, sortedIndexes, caseLabels); - - } else { codeStream.tableswitch( defaultLabel, min, @@ -839,7 +832,6 @@ public void generateCode(BlockScope currentScope, CodeStream codeStream) { sortedIndexes, this.constMapping, caseLabels); - } } else { codeStream.lookupswitch(defaultLabel, this.constants, sortedIndexes, caseLabels); } @@ -1110,11 +1102,9 @@ boolean isAllowedType(TypeBinding type) { @Override public void resolve(BlockScope upperScope) { try { - boolean isEnumSwitch = false; boolean isStringSwitch = false; TypeBinding expressionType = this.expression.resolveType(upperScope); CompilerOptions compilerOptions = upperScope.compilerOptions(); - boolean isEnhanced = checkAndSetEnhanced(upperScope, expressionType); if (expressionType != null) { this.expression.computeConversion(upperScope, expressionType, expressionType); checkType: { @@ -1130,15 +1120,11 @@ public void resolve(BlockScope upperScope) { if (expressionType.isCompatibleWith(TypeBinding.INT)) break checkType; } else if (expressionType.isEnum()) { - isEnumSwitch = true; - if (compilerOptions.complianceLevel < ClassFileConstants.JDK1_5) { - upperScope.problemReporter().incorrectSwitchType(this.expression, expressionType); // https://bugs.eclipse.org/bugs/show_bug.cgi?id=360317 - } break checkType; } else if (!this.containsPatterns && !this.containsNull && upperScope.isBoxingCompatibleWith(expressionType, TypeBinding.INT)) { this.expression.computeConversion(upperScope, TypeBinding.INT, expressionType); break checkType; - } else if (compilerOptions.complianceLevel >= ClassFileConstants.JDK1_7 && expressionType.id == TypeIds.T_JavaLangString) { + } else if (expressionType.id == TypeIds.T_JavaLangString) { if (this.containsPatterns || this.containsNull) { isStringSwitch = !JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(compilerOptions); this.isNonTraditional = true; @@ -1295,61 +1281,76 @@ && defaultFound && isExhaustive()) { } reportMixingCaseTypes(); - // check default case for non-enum switch: - boolean flagged = checkAndFlagDefaultSealed(upperScope, compilerOptions); - if (!flagged && this.defaultCase == null) { - if (ignoreMissingDefaultCase(compilerOptions, isEnumSwitch) && isEnumSwitch) { - upperScope.methodScope().hasMissingSwitchDefault = true; - } else { - if (!isEnumSwitch && !isExhaustive()) { + complainIfNotExhaustiveSwitch(upperScope, expressionType, compilerOptions); + + } finally { + if (this.scope != null) this.scope.enclosingCase = null; // no longer inside switch case block + } + } + private void complainIfNotExhaustiveSwitch(BlockScope upperScope, TypeBinding selectorType, CompilerOptions compilerOptions) { + + boolean isEnhanced = isEnhancedSwitch(upperScope, selectorType); + if (selectorType != null && selectorType.isEnum()) { + if (isEnhanced) + this.switchBits |= SwitchStatement.Exhaustive; // negated below if found otherwise + if (this.defaultCase != null && !compilerOptions.reportMissingEnumCaseDespiteDefault) + return; + + int constantCount = this.otherConstants == null ? 0 : this.otherConstants.length; + if (!((this.switchBits & TotalPattern) != 0) && + ((this.containsPatterns || this.containsNull) || + (constantCount >= this.caseCount && + constantCount != ((ReferenceBinding)selectorType).enumConstantCount()))) { + Set unenumeratedConstants = unenumeratedConstants((ReferenceBinding) selectorType, constantCount); + if (unenumeratedConstants.size() != 0) { + this.switchBits &= ~SwitchStatement.Exhaustive; + if (!(this.defaultCase != null && (this.defaultCase.bits & DocumentedCasesOmitted) != 0)) { if (isEnhanced) upperScope.problemReporter().enhancedSwitchMissingDefaultCase(this.expression); - else - upperScope.problemReporter().missingDefaultCase(this, isEnumSwitch, expressionType); - } - } - } - // Exhaustiveness check for enum switch - if (isEnumSwitch && compilerOptions.complianceLevel >= ClassFileConstants.JDK1_5) { - if (this.defaultCase == null || compilerOptions.reportMissingEnumCaseDespiteDefault) { - int constantCount = this.otherConstants == null ? 0 : this.otherConstants.length; - if (isEnhanced) - this.switchBits |= SwitchStatement.Exhaustive; // negated below if found otherwise - if (!((this.switchBits & TotalPattern) != 0) && - ((this.containsPatterns || this.containsNull) || - (constantCount >= this.caseCount && - constantCount != ((ReferenceBinding)expressionType).enumConstantCount()))) { - Set unenumeratedConstants = unenumeratedConstants((ReferenceBinding) expressionType, constantCount); - if (unenumeratedConstants.size() != 0) { - this.switchBits &= ~SwitchStatement.Exhaustive; - // enum constant did not get referenced from switch - boolean suppress = (this.defaultCase != null && (this.defaultCase.bits & DocumentedCasesOmitted) != 0); - if (!suppress) { - if (isEnhanced) - upperScope.problemReporter().enhancedSwitchMissingDefaultCase(this.expression); - else { - for (FieldBinding enumConstant : unenumeratedConstants) { - reportMissingEnumConstantCase(upperScope, enumConstant); - } - } + else { + for (FieldBinding enumConstant : unenumeratedConstants) { + reportMissingEnumConstantCase(upperScope, enumConstant); } } } } - if (this.defaultCase == null) { - if (ignoreMissingDefaultCase(compilerOptions, isEnumSwitch)) { - upperScope.methodScope().hasMissingSwitchDefault = true; - } else { - upperScope.problemReporter().missingDefaultCase(this, isEnumSwitch, expressionType); - } + } + + if (this.defaultCase == null) { + if (ignoreMissingDefaultCase(compilerOptions)) { + upperScope.methodScope().hasMissingSwitchDefault = true; + } else { + upperScope.problemReporter().missingDefaultCase(this, true, selectorType); } } - } finally { - if (this.scope != null) this.scope.enclosingCase = null; // no longer inside switch case block + return; + } + + if (isExhaustive() || this.defaultCase != null || selectorType == null) { + if (isEnhanced) + this.switchBits |= SwitchStatement.Exhaustive; + return; + } + + if (JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(compilerOptions) && selectorType.isSealed() && caseElementsCoverSealedType((ReferenceBinding) selectorType, this.caseLabelElementTypes)) { + this.switchBits |= SwitchStatement.Exhaustive; + return; + } + + if (selectorType.isRecordWithComponents() && this.containsRecordPatterns && caseElementsCoverRecordType(upperScope, compilerOptions, (ReferenceBinding) selectorType)) { + this.switchBits |= SwitchStatement.Exhaustive; + return; + } + + if (!isExhaustive()) { + if (isEnhanced) + upperScope.problemReporter().enhancedSwitchMissingDefaultCase(this.expression); + else + upperScope.problemReporter().missingDefaultCase(this, false, selectorType); } } - // Return the set of enumerations belonging to the selector enum type that are not listed in case statements. + // Return the set of enumerations belonging to the selector enum type that are NOT listed in case statements. private Set unenumeratedConstants(ReferenceBinding enumType, int constantCount) { FieldBinding[] enumFields = ((ReferenceBinding) enumType.erasure()).fields(); Set unenumerated = new HashSet<>(Arrays.asList(enumFields)); @@ -1389,9 +1390,9 @@ private boolean isExhaustive() { return (this.switchBits & SwitchStatement.Exhaustive) != 0; } - private boolean checkAndSetEnhanced(BlockScope upperScope, TypeBinding expressionType) { + private boolean isEnhancedSwitch(BlockScope upperScope, TypeBinding expressionType) { if (JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(upperScope.compilerOptions()) - && expressionType != null && !(this instanceof SwitchExpression )) { + && expressionType != null && !(this instanceof SwitchExpression)) { boolean acceptableType = !expressionType.isEnum(); switch (expressionType.id) { @@ -1415,7 +1416,7 @@ private boolean checkAndSetEnhanced(BlockScope upperScope, TypeBinding expressio return true; } } - if (expressionType != null && JavaFeature.PRIMITIVES_IN_PATTERNS.isSupported(upperScope.compilerOptions())) { + if (expressionType != null && !(this instanceof SwitchExpression) && JavaFeature.PRIMITIVES_IN_PATTERNS.isSupported(upperScope.compilerOptions())) { switch (expressionType.id) { case TypeIds.T_float: case TypeIds.T_double: @@ -1430,67 +1431,19 @@ private boolean checkAndSetEnhanced(BlockScope upperScope, TypeBinding expressio } return false; } - private boolean checkAndFlagDefaultSealed(BlockScope skope, CompilerOptions compilerOptions) { - if (this.defaultCase != null) { - this.switchBits |= SwitchStatement.Exhaustive; - return false; - } - if (this.expression.resolvedType instanceof ReferenceBinding ref && ref.isRecord()) { - boolean isRecordPattern = false; - for (Pattern pattern : this.caseLabelElements) { - if (pattern instanceof RecordPattern) { - isRecordPattern = true; - break; - } - } - if (isRecordPattern) - return checkAndFlagDefaultRecord(skope, compilerOptions, ref); - } - boolean checkSealed = JavaFeature.SEALED_CLASSES.isSupported(compilerOptions) - && JavaFeature.PATTERN_MATCHING_IN_SWITCH.isSupported(compilerOptions) - && this.expression.resolvedType instanceof ReferenceBinding - && this.expression.resolvedType.isSealed(); - - if (!checkSealed) return false; - ReferenceBinding ref = (ReferenceBinding) this.expression.resolvedType; - if (!(ref.isClass() || ref.isInterface() || ref.isTypeVariable() || ref.isIntersectionType())) - return false; - if (!caseElementsCoverSelectorType(ref.getAllEnumerableReferenceTypes(), this.caseLabelElementTypes)) { - if (this instanceof SwitchExpression) // non-exhaustive switch expressions will be flagged later. - return false; - skope.problemReporter().enhancedSwitchMissingDefaultCase(this.expression); - return true; - } - this.switchBits |= SwitchStatement.Exhaustive; - return false; - } - private boolean checkAndFlagDefaultRecord(BlockScope skope, CompilerOptions compilerOptions, ReferenceBinding ref) { - RecordComponentBinding[] comps = ref.components(); - List allallowedTypes = new ArrayList<>(); - allallowedTypes.add(ref); - if (comps == null || comps.length == 0) { - if (!caseElementsCoverSelectorType(allallowedTypes, this.caseLabelElementTypes)) { - skope.problemReporter().enhancedSwitchMissingDefaultCase(this.expression); - return true; - } - return false; - } - // non-zero components - RNode head = new RNode(ref); + private boolean caseElementsCoverRecordType(BlockScope skope, CompilerOptions compilerOptions, ReferenceBinding recordType) { + RNode head = new RNode(recordType); for (Pattern pattern : this.caseLabelElements) { head.addPattern(pattern); } CoverageCheckerVisitor ccv = new CoverageCheckerVisitor(); head.traverse(ccv); - if (!ccv.covers) { - skope.problemReporter().enhancedSwitchMissingDefaultCase(this.expression); - return true; // not exhaustive, error flagged - } - this.switchBits |= SwitchStatement.Exhaustive; - return false; + return ccv.covers; } - private boolean caseElementsCoverSelectorType(List allAllowedTypes, List listedTypes) { + + private boolean caseElementsCoverSealedType(ReferenceBinding sealedType, List listedTypes) { + List allAllowedTypes = sealedType.getAllEnumerableReferenceTypes(); Iterator iterator = allAllowedTypes.iterator(); while (iterator.hasNext()) { ReferenceBinding next = iterator.next(); @@ -1554,7 +1507,7 @@ private void addSecretPatternSwitchVariables(BlockScope upperScope) { protected void reportMissingEnumConstantCase(BlockScope upperScope, FieldBinding enumConstant) { upperScope.problemReporter().missingEnumConstantCase(this, enumConstant); } - protected boolean ignoreMissingDefaultCase(CompilerOptions compilerOptions, boolean isEnumSwitch) { + protected boolean ignoreMissingDefaultCase(CompilerOptions compilerOptions) { return compilerOptions.getSeverity(CompilerOptions.MissingDefaultCase) == ProblemSeverities.Ignore; } @Override diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/impl/JavaFeature.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/impl/JavaFeature.java index 2edf0038c14..09b4cbe1428 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/impl/JavaFeature.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/impl/JavaFeature.java @@ -56,7 +56,7 @@ public enum JavaFeature { SEALED_CLASSES(ClassFileConstants.JDK17, Messages.bind(Messages.sealed_types), - new char[][] {TypeConstants.SEALED, TypeConstants.PERMITS}, + new char[][] {TypeConstants.SEALED, TypeConstants.NON_SEALED, TypeConstants.PERMITS}, false), PATTERN_MATCHING_IN_SWITCH(ClassFileConstants.JDK21, Messages.bind(Messages.pattern_matching_switch), diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java index a0a9cc5e1d1..5b2d5017050 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/ReferenceBinding.java @@ -65,7 +65,6 @@ import org.eclipse.jdt.internal.compiler.ast.NullAnnotationMatching; import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants; import org.eclipse.jdt.internal.compiler.impl.CompilerOptions; -import org.eclipse.jdt.internal.compiler.impl.JavaFeature; import org.eclipse.jdt.internal.compiler.impl.ReferenceContext; import org.eclipse.jdt.internal.compiler.util.SimpleLookupTable; @@ -2368,10 +2367,8 @@ public MethodBinding getSingleAbstractMethod(Scope scope, boolean replaceWildcar return this.singleAbstractMethod[index]; } else { this.singleAbstractMethod = new MethodBinding[2]; - // Sec 9.8 of sealed preview - A functional interface is an interface that is not declared sealed... - if (JavaFeature.SEALED_CLASSES.isSupported(scope.compilerOptions()) - && this.isSealed()) - return this.singleAbstractMethod[index] = samProblemBinding; + if (this.isSealed()) + return this.singleAbstractMethod[index] = samProblemBinding; // JLS 9.8 } if (this.compoundName != null) diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java index 808d5b34985..c7479f912f0 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeBinding.java @@ -703,6 +703,10 @@ public boolean isRecord() { return false; } +public boolean isRecordWithComponents() { // do records without components make sense ??! + return isRecord() && components() instanceof RecordComponentBinding [] components && components.length > 0; +} + /* Answer true if the receiver type can be assigned to the argument type (right) */ public boolean isCompatibleWith(TypeBinding right) { diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java index f9e2d8a59b6..2a72d85fa51 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/lookup/TypeConstants.java @@ -130,6 +130,7 @@ public interface TypeConstants { // JEP 360 Sealed char[] PERMITS = "permits".toCharArray(); //$NON-NLS-1$ char[] SEALED = "sealed".toCharArray(); //$NON-NLS-1$ + char[] NON_SEALED = "non-sealed".toCharArray(); //$NON-NLS-1$ String KEYWORD_EXTENDS = "extends"; //$NON-NLS-1$ String IMPLEMENTS = "implements"; //$NON-NLS-1$ diff --git a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java index 6c32f715eac..6b07efd14d8 100644 --- a/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java +++ b/org.eclipse.jdt.core.compiler.batch/src/org/eclipse/jdt/internal/compiler/parser/Parser.java @@ -9936,7 +9936,6 @@ protected void consumeToken(int type) { pushOnIntStack(this.scanner.startPosition); break; case TokenNameRestrictedIdentifierpermits: - problemReporter().validateJavaFeatureSupport(JavaFeature.SEALED_CLASSES, this.scanner.startPosition,this.scanner.currentPosition - 1); pushOnIntStack(this.scanner.startPosition); break; case TokenNamecase : diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PrimitiveInPatternsTestSH.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PrimitiveInPatternsTestSH.java index 3fd75e95630..418e0baef13 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PrimitiveInPatternsTestSH.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/PrimitiveInPatternsTestSH.java @@ -1919,7 +1919,7 @@ static int m1(boolean b) { 1. ERROR in X.java (at line 3) return switch (b) { ^ - An enhanced switch statement should be exhaustive; a default label expected + A switch expression should have a default case ---------- """); } @@ -2116,12 +2116,12 @@ static double m2(long l) { 1. ERROR in X.java (at line 3) return switch(l) { ^ - An enhanced switch statement should be exhaustive; a default label expected + A switch expression should have a default case ---------- 2. ERROR in X.java (at line 9) return switch(l) { ^ - An enhanced switch statement should be exhaustive; a default label expected + A switch expression should have a default case ---------- """); } diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordPatternTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordPatternTest.java index 33937c7e4ea..aa3198e6fa4 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordPatternTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/RecordPatternTest.java @@ -2669,7 +2669,7 @@ public void testRecPatExhaust002() { "1. ERROR in X.java (at line 12)\n" + " return switch (box) { // Not Exhaustive!\n" + " ^^^\n" + - "An enhanced switch statement should be exhaustive; a default label expected\n" + + "A switch expression should have a default case\n" + "----------\n"); } public void testRecPatExhaust003() { @@ -2753,7 +2753,7 @@ public void testRecPatExhaust004() { "1. ERROR in X.java (at line 16)\n" + " return switch (box) { // Not Exhaustive!\n" + " ^^^\n" + - "An enhanced switch statement should be exhaustive; a default label expected\n" + + "A switch expression should have a default case\n" + "----------\n"); } public void testRecPatExhaust005() { @@ -2816,7 +2816,7 @@ public void testRecPatExhaust006() { "1. ERROR in X.java (at line 11)\n" + " return switch (box) { // Not Exhaustive!\n" + " ^^^\n" + - "An enhanced switch statement should be exhaustive; a default label expected\n" + + "A switch expression should have a default case\n" + "----------\n"); } public void testRecPatExhaust007() { @@ -2849,7 +2849,7 @@ public void testRecPatExhaust007() { "1. ERROR in X.java (at line 12)\n" + " return switch (p) { // Not Exhaustive!\n" + " ^\n" + - "An enhanced switch statement should be exhaustive; a default label expected\n" + + "A switch expression should have a default case\n" + "----------\n"); } public void testRecPatExhaust008() { @@ -2883,7 +2883,7 @@ public void testRecPatExhaust008() { "1. ERROR in X.java (at line 12)\n" + " return switch (p) { // Not Exhaustive!\n" + " ^\n" + - "An enhanced switch statement should be exhaustive; a default label expected\n" + + "A switch expression should have a default case\n" + "----------\n"); } public void testRecPatExhaust009() { @@ -2961,7 +2961,7 @@ public void testRecPatExhaust011() { "1. ERROR in X.java (at line 12)\n" + " return switch (r) {\n" + " ^\n" + - "An enhanced switch statement should be exhaustive; a default label expected\n" + + "A switch expression should have a default case\n" + "----------\n"); } // implicit permitted - class @@ -2994,7 +2994,7 @@ public void testRecPatExhaust012() { "1. ERROR in X.java (at line 12)\n" + " return switch (r) {\n" + " ^\n" + - "An enhanced switch statement should be exhaustive; a default label expected\n" + + "A switch expression should have a default case\n" + "----------\n"); } // implicit permitted - class - the class C missing @@ -3028,7 +3028,7 @@ public void testRecPatExhaust013() { "1. ERROR in X.java (at line 12)\n" + " return switch (r) {\n" + " ^\n" + - "An enhanced switch statement should be exhaustive; a default label expected\n" + + "A switch expression should have a default case\n" + "----------\n"); } public void testRecPatExhaust014() { @@ -3061,7 +3061,7 @@ public void testRecPatExhaust014() { "1. ERROR in X.java (at line 11)\n" + " return switch (r) {\n" + " ^\n" + - "An enhanced switch statement should be exhaustive; a default label expected\n" + + "A switch expression should have a default case\n" + "----------\n"); } public void testRecPatExhaust015() { @@ -3177,7 +3177,7 @@ public void testRecPatExhaust018() { "1. ERROR in X.java (at line 12)\n" + " return switch (r) {\n" + " ^\n" + - "An enhanced switch statement should be exhaustive; a default label expected\n" + + "A switch expression should have a default case\n" + "----------\n"); } public void testRecordPatternTypeInference_012() { diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java index 300b50edee8..a802d08ba5e 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchPatternTest.java @@ -29,7 +29,6 @@ public class SwitchPatternTest extends AbstractRegressionTest9 { // TESTS_NUMBERS = new int [] { 40 }; // TESTS_RANGE = new int[] { 1, -1 }; // TESTS_NAMES = new String[] { "testBug575053_002"}; -// TESTS_NAMES = new String[] { "testBug575571_1"}; } private static String previewLevel = "21"; diff --git a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java index 0135b00b79e..ca941fc187b 100644 --- a/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java +++ b/org.eclipse.jdt.core.tests.compiler/src/org/eclipse/jdt/core/tests/compiler/regression/SwitchTest.java @@ -2569,17 +2569,12 @@ public void test383643() { " ^\n" + "p cannot be resolved to a variable\n" + "----------\n" + - "2. WARNING in X.java (at line 4)\n" + - " switch (p) {\n" + - " ^\n" + - "The switch statement should have a default case\n" + - "----------\n" + - "3. ERROR in X.java (at line 5)\n" + + "2. ERROR in X.java (at line 5)\n" + " case ONE:\n" + " ^^^\n" + "ONE cannot be resolved to a variable\n" + "----------\n" + - "4. ERROR in X.java (at line 8)\n" + + "3. ERROR in X.java (at line 8)\n" + " case TWO:\n" + " ^^^\n" + "TWO cannot be resolved to a variable\n" +