Unbox inline classes after safe calls if needed
This commit is contained in:
@@ -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;
|
||||
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// !LANGUAGE: +InlineClasses
|
||||
|
||||
inline class Foo(val x: Int) {
|
||||
fun member() {}
|
||||
}
|
||||
|
||||
fun Foo.extension() {}
|
||||
fun <T> T.genericExtension() {}
|
||||
|
||||
fun test(f: Foo?) {
|
||||
f?.member() // unbox
|
||||
f?.extension() // unbox
|
||||
f?.genericExtension()
|
||||
}
|
||||
|
||||
// 0 INVOKESTATIC Foo\$Erased.box
|
||||
// 2 INVOKEVIRTUAL Foo.unbox
|
||||
|
||||
// 0 valueOf
|
||||
// 0 intValue
|
||||
Reference in New Issue
Block a user