Skip to content

Commit d17e312

Browse files
graememorganError Prone Team
authored andcommitted
Add a regression test for a crash in MissingCasesInEnumSwitch when using an expression switch with RULE cases.
I had no idea this was allowed. I think I internalised expression switches and statement cases as being inextricably coupled. I am now worried I have leaked a bad assumption into other places! PiperOrigin-RevId: 779180644
1 parent 7d8fd68 commit d17e312

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

core/src/test/java/com/google/errorprone/bugpatterns/MissingCasesInEnumSwitchTest.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
package com.google.errorprone.bugpatterns;
1818

1919
import static com.google.common.truth.TruthJUnit.assume;
20+
import static org.junit.Assert.assertThrows;
2021

2122
import com.google.errorprone.CompilationTestHelper;
2223
import org.junit.Test;
@@ -482,4 +483,28 @@ void m(Case c) {
482483
""")
483484
.doTest();
484485
}
486+
487+
@Test
488+
public void defaultInRuleCase_crash() {
489+
compilationHelper.addSourceLines(
490+
"Test.java",
491+
"""
492+
public class Test {
493+
public enum E {
494+
A,
495+
B
496+
}
497+
498+
public static Object test(E e) {
499+
return switch (e) {
500+
case A:
501+
yield new Object();
502+
default:
503+
yield null;
504+
};
505+
}
506+
}
507+
""");
508+
assertThrows(AssertionError.class, () -> compilationHelper.doTest());
509+
}
485510
}

0 commit comments

Comments
 (0)