File tree Expand file tree Collapse file tree
src/jdk.compiler/share/classes/com/sun/tools/javac/parser
test/langtools/tools/javac/switchexpr Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2668,6 +2668,9 @@ List<JCStatement> blockStatement() {
26682668 case PLUSPLUS : case SUBSUB :
26692669 isYieldStatement = S .token (2 ).kind != SEMI ;
26702670 break ;
2671+ case BANG : case TILDE :
2672+ isYieldStatement = S .token (1 ).kind != SEMI ;
2673+ break ;
26712674 case LPAREN :
26722675 int lookahead = 2 ;
26732676 int balance = 1 ;
Original file line number Diff line number Diff line change 11/*
22 * @test /nodynamiccopyright/
3- * @bug 8206986 8222169 8224031 8240964 8267119
3+ * @bug 8206986 8222169 8224031 8240964 8267119 8268670
44 * @summary Check expression switch works.
55 * @compile/fail/ref=ExpressionSwitch-old.out -source 9 -Xlint:-options -XDrawDiagnostics ExpressionSwitch.java
66 * @compile ExpressionSwitch.java
@@ -120,6 +120,26 @@ private Object yieldDisambiguationLiterals(String s) {
120120 };
121121 }
122122
123+ private int yieldUnaryNumberOperator (String s , int a ) {
124+ return switch (s ) {
125+ case "a" : yield +a ;
126+ case "b" : yield -a ;
127+ case "c" : yield ~a ; // intentionally repeated ~a, test the case clause
128+ case "d" : yield ++a ;
129+ case "e" : yield --a ;
130+ case "f" : yield a ++;
131+ case "g" : yield a --;
132+ default : yield ~a ; // intentionally repeated ~a, test the default clause
133+ };
134+ }
135+
136+ private boolean yieldUnaryNotOperator (String s , boolean b ) {
137+ return switch (s ) {
138+ case "a" : yield !b ; // intentionally repeated !b, test the case clause
139+ default : yield !b ; // intentionally repeated !b, test the default clause
140+ };
141+ }
142+
123143 private void localClass (T t ) {
124144 String good = "good" ;
125145 class L {
You can’t perform that action at this time.
0 commit comments