Skip to content

Commit

Permalink
Test failures in I-Builds due to less diagnostics being emitted (#3357)
Browse files Browse the repository at this point in the history
* Fixes #3356
  • Loading branch information
srikanth-sankaran authored Nov 27, 2024
1 parent 54be506 commit 386474a
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,9 @@ private Constant resolveConstantLabel(BlockScope scope, TypeBinding caseType, Ty

CompilerOptions options = scope.compilerOptions();
if (caseType.isEnum() && caseType.isCompatibleWith(selectorType)) {
if (((expression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) != 0) {
if (((expression.bits & ASTNode.ParenthesizedMASK) >> ASTNode.ParenthesizedSHIFT) != 0)
scope.problemReporter().enumConstantsCannotBeSurroundedByParenthesis(expression);
return Constant.NotAConstant;
}

if (expression instanceof NameReference reference && reference.binding instanceof FieldBinding field) {
if ((field.modifiers & ClassFileConstants.AccEnum) == 0)
scope.problemReporter().enumSwitchCannotTargetField(reference, field);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7428,4 +7428,51 @@ void k() {
"Cannot make a static reference to the non-static field h\n" +
"----------\n");
}
// https://github.com/eclipse-jdt/eclipse.jdt.core/issues/3356
// Test failures in I-Builds due to less diagnostics being emitted
public void testIssue3356() {
this.runNegativeTest(new String[] {
"X.java",
"""
public class X {
public enum color {black, white}
public void foo(color c) {
switch (c) {
case (color.black):
System.out.println("Black");
break;
}
}
}
"""
},
this.complianceLevel < ClassFileConstants.JDK21 ?
"----------\n" +
"1. WARNING in X.java (at line 4)\n" +
" switch (c) {\n" +
" ^\n" +
"The enum constant white needs a corresponding case label in this enum switch on X.color\n" +
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" case (color.black):\n" +
" ^^^^^^^^^^^^^\n" +
"Enum constants cannot be surrounded by parenthesis\n" +
"----------\n" +
"3. ERROR in X.java (at line 5)\n" +
" case (color.black):\n" +
" ^^^^^^^^^^^^^\n" +
"The qualified case label X.color.black must be replaced with the unqualified enum constant black\n" +
"----------\n"
: "----------\n" +
"1. WARNING in X.java (at line 4)\n" +
" switch (c) {\n" +
" ^\n" +
"The enum constant white needs a corresponding case label in this enum switch on X.color\n" +
"----------\n" +
"2. ERROR in X.java (at line 5)\n" +
" case (color.black):\n" +
" ^^^^^^^^^^^^^\n" +
"Enum constants cannot be surrounded by parenthesis\n" +
"----------\n");
}
}

0 comments on commit 386474a

Please sign in to comment.