Propagate KotlinType into when expression codegen
This commit removes unneeded boxing when result expression of `when` is value of inline class type
This commit is contained in:
@@ -4573,8 +4573,9 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
|
|
||||||
public StackValue generateWhenExpression(KtWhenExpression expression, boolean isStatement) {
|
public StackValue generateWhenExpression(KtWhenExpression expression, boolean isStatement) {
|
||||||
Type resultType = isStatement ? Type.VOID_TYPE : expressionType(expression);
|
Type resultType = isStatement ? Type.VOID_TYPE : expressionType(expression);
|
||||||
|
KotlinType resultKotlinType = isStatement ? null : kotlinType(expression);
|
||||||
|
|
||||||
return StackValue.operation(resultType, v -> {
|
return StackValue.operation(resultType, resultKotlinType, v -> {
|
||||||
KtProperty subjectVariable = expression.getSubjectVariable();
|
KtProperty subjectVariable = expression.getSubjectVariable();
|
||||||
KtExpression subjectExpression = expression.getSubjectExpression();
|
KtExpression subjectExpression = expression.getSubjectExpression();
|
||||||
|
|
||||||
@@ -4637,7 +4638,7 @@ The "returned" value of try expression with no finally is either the last expres
|
|||||||
}
|
}
|
||||||
|
|
||||||
v.visitLabel(thisEntry);
|
v.visitLabel(thisEntry);
|
||||||
gen(whenEntry.getExpression(), resultType);
|
gen(whenEntry.getExpression(), resultType, resultKotlinType);
|
||||||
mark.dropTo();
|
mark.dropTo();
|
||||||
if (!whenEntry.isElse()) {
|
if (!whenEntry.isElse()) {
|
||||||
v.goTo(end);
|
v.goTo(end);
|
||||||
|
|||||||
@@ -0,0 +1,18 @@
|
|||||||
|
// !LANGUAGE: +InlineClasses
|
||||||
|
|
||||||
|
inline class Foo<T>(val x: Any) {
|
||||||
|
fun bar() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun <T, K> transform(f: Foo<T>): Foo<K> {
|
||||||
|
return when {
|
||||||
|
true -> f as Foo<K>
|
||||||
|
else -> TODO()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
val f = Foo<Int>(42)
|
||||||
|
val t = transform<Int, Number>(f)
|
||||||
|
return if (t.x !is Number) "Fail" else "OK"
|
||||||
|
}
|
||||||
Generated
+5
@@ -11021,6 +11021,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/callableReferencesWithInlineClasses.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/callableReferencesWithInlineClasses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("castInsideWhenExpression.kt")
|
||||||
|
public void testCastInsideWhenExpression() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/castInsideWhenExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
||||||
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
||||||
|
|||||||
+5
@@ -11021,6 +11021,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/callableReferencesWithInlineClasses.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/callableReferencesWithInlineClasses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("castInsideWhenExpression.kt")
|
||||||
|
public void testCastInsideWhenExpression() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/castInsideWhenExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
||||||
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
||||||
|
|||||||
+5
@@ -11021,6 +11021,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/callableReferencesWithInlineClasses.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/callableReferencesWithInlineClasses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("castInsideWhenExpression.kt")
|
||||||
|
public void testCastInsideWhenExpression() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/castInsideWhenExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
||||||
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
||||||
|
|||||||
+5
@@ -9671,6 +9671,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/callableReferencesWithInlineClasses.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/callableReferencesWithInlineClasses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("castInsideWhenExpression.kt")
|
||||||
|
public void testCastInsideWhenExpression() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/castInsideWhenExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
||||||
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
||||||
|
|||||||
+5
@@ -9671,6 +9671,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/inlineClasses/callableReferencesWithInlineClasses.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/callableReferencesWithInlineClasses.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("castInsideWhenExpression.kt")
|
||||||
|
public void testCastInsideWhenExpression() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/inlineClasses/castInsideWhenExpression.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
@TestMetadata("checkBoxUnboxOfArgumentsOnInlinedFunctions.kt")
|
||||||
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
public void testCheckBoxUnboxOfArgumentsOnInlinedFunctions() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
runTest("compiler/testData/codegen/box/inlineClasses/checkBoxUnboxOfArgumentsOnInlinedFunctions.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user