KT-35004: keep track of KotlinType for 'when' subject

This commit is contained in:
Dmitry Petrov
2019-11-20 13:08:13 +03:00
parent 338b4e2eab
commit d3a5dcb601
8 changed files with 43 additions and 2 deletions
@@ -5071,11 +5071,11 @@ The "returned" value of try expression with no finally is either the last expres
private StackValue generateWhenCondition(KtExpression subjectExpression, Type subjectType, KotlinType subjectKotlinType, int subjectLocal, KtWhenCondition condition) {
if (condition instanceof KtWhenConditionInRange) {
KtWhenConditionInRange conditionInRange = (KtWhenConditionInRange) condition;
return generateIn(StackValue.local(subjectLocal, subjectType),
return generateIn(StackValue.local(subjectLocal, subjectType, subjectKotlinType),
conditionInRange.getRangeExpression(),
conditionInRange.getOperationReference());
}
StackValue.Local match = subjectLocal == -1 ? null : StackValue.local(subjectLocal, subjectType);
StackValue.Local match = subjectLocal == -1 ? null : StackValue.local(subjectLocal, subjectType, subjectKotlinType);
if (condition instanceof KtWhenConditionIsPattern) {
KtWhenConditionIsPattern patternCondition = (KtWhenConditionIsPattern) condition;
return generateIsCheck(match, patternCondition.getTypeReference(), patternCondition.isNegated());
@@ -0,0 +1,11 @@
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
// KJS_WITH_FULL_RUNTIME
fun ULong.foobar() =
when (this) {
in 0U..1U -> "OK"
else -> throw AssertionError("$this")
}
fun box(): String = 0UL.foobar()
@@ -21998,6 +21998,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/ranges/unsigned/inMixedUnsignedRange.kt");
}
@TestMetadata("kt35004.kt")
public void testKt35004() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
}
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -20815,6 +20815,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/ranges/unsigned/inMixedUnsignedRange.kt");
}
@TestMetadata("kt35004.kt")
public void testKt35004() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
}
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -20533,6 +20533,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/ranges/unsigned/inMixedUnsignedRange.kt");
}
@TestMetadata("kt35004.kt")
public void testKt35004() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
}
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -20533,6 +20533,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/ranges/unsigned/inMixedUnsignedRange.kt");
}
@TestMetadata("kt35004.kt")
public void testKt35004() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
}
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -17683,6 +17683,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/ranges/unsigned/inMixedUnsignedRange.kt");
}
@TestMetadata("kt35004.kt")
public void testKt35004() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
}
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
@@ -18813,6 +18813,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/ranges/unsigned/inMixedUnsignedRange.kt");
}
@TestMetadata("kt35004.kt")
public void testKt35004() throws Exception {
runTest("compiler/testData/codegen/box/ranges/unsigned/kt35004.kt");
}
@TestMetadata("compiler/testData/codegen/box/ranges/unsigned/expression")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)