Unbox inline classes after safe calls if needed

This commit is contained in:
Mikhail Zarechenskiy
2018-02-05 13:50:22 +03:00
parent c5c8d84719
commit 0fd80ce980
3 changed files with 31 additions and 3 deletions
@@ -423,6 +423,11 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
return CodegenUtilKt.asmType(expression, typeMapper, bindingContext);
}
@Nullable
public KotlinType kotlinType(@Nullable KtExpression expression) {
return CodegenUtilKt.kotlinType(expression, bindingContext);
}
@Override
public StackValue visitParenthesizedExpression(@NotNull KtParenthesizedExpression expression, StackValue receiver) {
return genQualified(receiver, expression.getExpression());
@@ -2929,10 +2934,13 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
KtExpression selector = expression.getSelectorExpression();
Type receiverType = expressionType(receiver);
KotlinType receiverKotlinType = kotlinType(receiver);
StackValue receiverValue = generateExpressionWithNullFallback(receiver, ifNull);
//Do not optimize for primitives cause in case of safe call extension receiver should be generated before dispatch one
StackValue newReceiver = new StackValue.SafeCall(receiverType, receiverValue, isPrimitive(receiverType) ? null : ifNull);
StackValue newReceiver = new StackValue.SafeCall(
receiverType, receiverKotlinType, receiverValue, isPrimitive(receiverType) ? null : ifNull
);
return genQualified(newReceiver, selector);
}
@@ -1925,8 +1925,8 @@ public abstract class StackValue {
private final StackValue receiver;
@Nullable private final Label ifNull;
public SafeCall(@NotNull Type type, @NotNull StackValue value, @Nullable Label ifNull) {
super(type);
public SafeCall(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull StackValue value, @Nullable Label ifNull) {
super(type, kotlinType);
this.type = type;
this.receiver = value;
this.ifNull = ifNull;