Fix safe calls codegen for nullable generic
This commit is contained in:
@@ -2228,11 +2228,9 @@ public class ExpressionCodegen extends JetVisitor<StackValue, StackValue> implem
|
||||
@Override
|
||||
public StackValue visitSafeQualifiedExpression(JetSafeQualifiedExpression expression, StackValue receiver) {
|
||||
JetExpression expr = expression.getReceiverExpression();
|
||||
JetType receiverJetType = bindingContext.get(BindingContext.EXPRESSION_TYPE, expression.getReceiverExpression());
|
||||
assert receiverJetType != null;
|
||||
Type receiverType = asmType(receiverJetType);
|
||||
Type receiverType = expressionType(expr);
|
||||
gen(expr, receiverType);
|
||||
if (!receiverJetType.isNullable()) {
|
||||
if (isPrimitive(receiverType)) {
|
||||
StackValue propValue = genQualified(StackValue.onStack(receiverType), expression.getSelectorExpression());
|
||||
Type type = boxType(propValue.type);
|
||||
propValue.put(type, v);
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fun foo<T : Number?>(t: T) {
|
||||
t?.toInt()
|
||||
}
|
||||
|
||||
fun box(): String {
|
||||
foo<Int?>(null)
|
||||
return "OK"
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
fun Int.foo() = 239
|
||||
fun Long.bar() = 239.toLong()
|
||||
|
||||
fun box(): String {
|
||||
42?.foo()
|
||||
42.toLong()?.bar()
|
||||
return "OK"
|
||||
}
|
||||
@@ -3050,6 +3050,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/codegen/box/safeCall"), "kt", true);
|
||||
}
|
||||
|
||||
@TestMetadata("genericNull.kt")
|
||||
public void testGenericNull() throws Exception {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/safeCall/genericNull.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("kt1572.kt")
|
||||
public void testKt1572() throws Exception {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/safeCall/kt1572.kt");
|
||||
@@ -3070,6 +3075,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/safeCall/kt247.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("primitive.kt")
|
||||
public void testPrimitive() throws Exception {
|
||||
blackBoxFileByFullPath("compiler/testData/codegen/box/safeCall/primitive.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/box/strings")
|
||||
|
||||
Reference in New Issue
Block a user