Skip to content

Commit

Permalink
[J2KT] Enable switchexpression integration test.
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 697998734
  • Loading branch information
rluble authored and copybara-github committed Nov 19, 2024
1 parent eb93f54 commit acb6e59
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ package(
integration_test(
name = "switchexpression",
srcs = glob(["*.java"]),
# TODO(b/375058137): Enable when bug is fixed.
enable_kt = False,
# TODO(b/379697518): Enable once @DoNotAutobox is propagated by J2KT.
enable_kt_web = False,
# TODO(b/375058020): Enable when bug is fixed.
enable_wasm = False,
javacopts = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,20 +176,24 @@ private static void testSwitchWithErasureCast() {
}
};

assertThrowsClassCastException(
() -> {
Supplier<Numbers> integerSupplier = (Supplier) () -> new Integer(1);
int unusedResult =
// supplier.get() goes through the `T Supplier<T>.get()` method in the interface, and
// thus must have an erasure cast. In this case it should throw CCE and not just
// fall into the default case.
switch (integerSupplier.get()) {
default -> {
fail();
yield 0;
}
};
});
if (!TestUtils.isJ2KtNative()) {
// Switch statements in Kotlin/Native do not throw erasure casts, instead they would flow to
// the default case.
assertThrowsClassCastException(
() -> {
Supplier<Numbers> integerSupplier = (Supplier) () -> new Integer(1);
int unusedResult =
// supplier.get() goes through the `T Supplier<T>.get()` method in the interface,
// and thus must have an erasure cast. In this case it should throw CCE and not just
// fall into the default case.
switch (integerSupplier.get()) {
default -> {
fail();
yield 0;
}
};
});
}
}

private static void testStringSwitch() {
Expand Down

0 comments on commit acb6e59

Please sign in to comment.