Files
openide/java/java-tests/testData/codeInsight/daemonCodeAnalyzer/switchExpressions/SwitchExpressionsNoResult.java
Anna Kozlova 1705f01347 [java] lambda context: allow conditional with lambda branches in switch cases (IDEA-269928)
extract cast processing to the upper level as it's not allowed in conditions (^Tagir)

GitOrigin-RevId: 3e608c133d2b44d67f9b57721fbf62c04c2c4147
2021-05-26 19:26:22 +00:00

37 lines
974 B
Java

class Test {
void test() {
int i = <error descr="Switch expression does not have any result expressions">switch</error>(0) {
default -> throw new NullPointerException();
};
}
void test2() {
int i = <error descr="Switch expression does not have any result expressions">switch</error>(0) {
case 0 -> {while(true);}
case 1 -> {
throw new RuntimeException();
}
default -> throw new NullPointerException();
};
}
void positive() {
int i = switch(0) {
case 4 -> 2;
default -> throw new NullPointerException();
};
}
Runnable lambdaContext(int x) {
return switch (x) {
default -> x > 0 ? () -> {} : () -> {};
};
}
Object invalidLambdaContext(int x) {
return (Runnable) switch (x) {
default -> x > 0 ? <error descr="Lambda expression not expected here">() -> {}</error> : <error descr="Lambda expression not expected here">() -> {}</error>;
};
}
}