This repository was archived by the owner on Sep 19, 2023. It is now read-only.
Commit b6827ff 1 parent a08c6b9 commit b6827ff Copy full SHA for b6827ff
File tree 3 files changed +33
-2
lines changed
src/jdk.compiler/share/classes/com/sun/tools/javac/comp
3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -1734,6 +1734,8 @@ private void handleSwitch(JCTree switchTree,
1734
1734
Symbol enumSym = TreeInfo .symbol (expr );
1735
1735
if (enumSym == null || !enumSym .isEnum () || enumSym .kind != VAR ) {
1736
1736
log .error (expr .pos (), Errors .EnumLabelMustBeEnumConstant );
1737
+ } else if (!constants .add (enumSym )) {
1738
+ log .error (label .pos (), Errors .DuplicateCaseLabel );
1737
1739
}
1738
1740
} else {
1739
1741
log .error (expr .pos (), Errors .EnumLabelMustBeUnqualifiedEnum );
@@ -1765,6 +1767,8 @@ private void handleSwitch(JCTree switchTree,
1765
1767
(stringSwitch ? Errors .StringConstReq
1766
1768
: intSwitch ? Errors .ConstExprReq
1767
1769
: Errors .PatternOrEnumReq ));
1770
+ } else if (!constants .add (s )) {
1771
+ log .error (label .pos (), Errors .DuplicateCaseLabel );
1768
1772
}
1769
1773
} else if (!stringSwitch && !intSwitch ) {
1770
1774
log .error (label .pos (), Errors .ConstantLabelNotCompatible (pattype , seltype ));
Original file line number Diff line number Diff line change 23
23
24
24
/**
25
25
* @test
26
- * @bug 8300543 8309336
26
+ * @bug 8300543 8309336 8311825
27
27
* @summary Check switches work correctly with qualified enum constants
28
28
* @compile/fail/ref=EnumSwitchQualifiedErrors.out -XDrawDiagnostics EnumSwitchQualifiedErrors.java
29
29
*/
@@ -69,6 +69,30 @@ int testPatternMatchingSwitch5(Object e) {
69
69
};
70
70
}
71
71
72
+ int testQualifiedDuplicate1 (Object o ) {
73
+ return switch (o ) {
74
+ case E1 .A -> 1 ;
75
+ case E1 .A -> 2 ;
76
+ default -> -1 ;
77
+ };
78
+ }
79
+
80
+ int testQualifiedDuplicate2 (E1 e ) {
81
+ return switch (e ) {
82
+ case A -> 1 ;
83
+ case E1 .A -> 2 ;
84
+ default -> -1 ;
85
+ };
86
+ }
87
+
88
+ int testQualifiedDuplicate3 (E1 e ) {
89
+ return switch (e ) {
90
+ case E1 .A -> 1 ;
91
+ case A -> 2 ;
92
+ default -> -1 ;
93
+ };
94
+ }
95
+
72
96
sealed interface I {}
73
97
enum E1 implements I { A ; }
74
98
enum E2 { A ; }
Original file line number Diff line number Diff line change @@ -8,4 +8,7 @@ EnumSwitchQualifiedErrors.java:58:18: compiler.err.enum.label.must.be.enum.const
8
8
EnumSwitchQualifiedErrors.java:65:18: compiler.err.pattern.or.enum.req
9
9
EnumSwitchQualifiedErrors.java:66:18: compiler.err.pattern.or.enum.req
10
10
EnumSwitchQualifiedErrors.java:67:18: compiler.err.pattern.expected
11
- 10 errors
11
+ EnumSwitchQualifiedErrors.java:75:18: compiler.err.duplicate.case.label
12
+ EnumSwitchQualifiedErrors.java:83:18: compiler.err.duplicate.case.label
13
+ EnumSwitchQualifiedErrors.java:91:18: compiler.err.duplicate.case.label
14
+ 13 errors
You can’t perform that action at this time.
0 commit comments