Add KotlinType info about this inside inline class

This commit is contained in:
Mikhail Zarechenskiy
2018-02-08 14:18:17 +03:00
parent c86d3e354b
commit 22b9c25dd0
9 changed files with 81 additions and 2 deletions
@@ -2678,8 +2678,8 @@ public class ExpressionCodegen extends KtVisitor<StackValue, StackValue> impleme
private StackValue generateThisOrOuterFromContext(@NotNull ClassDescriptor thisOrOuterClass, boolean isSuper, boolean forceOuter) {
CodegenContext cur = context;
Type type = asmType(thisOrOuterClass.getDefaultType());
StackValue result = StackValue.local(0, type);
SimpleType thisType = thisOrOuterClass.getDefaultType();
StackValue result = StackValue.local(0, asmType(thisType), thisType);
boolean inStartConstructorContext = cur instanceof ConstructorContext;
while (cur != null) {
ClassDescriptor thisDescriptor = cur.getThisDescriptor();
@@ -151,6 +151,10 @@ public abstract class StackValue {
return new Local(index, type);
}
public static Local local(int index, @NotNull Type type, @Nullable KotlinType kotlinType) {
return new Local(index, type, kotlinType);
}
@NotNull
public static Local local(int index, @NotNull Type type, @NotNull VariableDescriptor descriptor) {
return new Local(index, type, descriptor.getType(), descriptor.isLateInit(), descriptor.getName());
@@ -802,6 +806,10 @@ public abstract class StackValue {
this(index, type, null, false, null);
}
private Local(int index, Type type, KotlinType kotlinType) {
this(index, type, kotlinType, false, null);
}
@Override
public void putSelector(@NotNull Type type, @Nullable KotlinType kotlinType, @NotNull InstructionAdapter v) {
v.load(index, this.type);
@@ -0,0 +1,21 @@
// !LANGUAGE: +InlineClasses
inline class UInt(val a: Int) {
fun test() {
takeNullable(this)
takeAnyInside(this)
takeAnyInside(this.a)
}
fun takeAnyInside(a: Any) {}
}
fun takeNullable(a: UInt?) {}
fun box(): String {
val a = UInt(0)
a.test()
return "OK"
}
@@ -0,0 +1,20 @@
// !LANGUAGE: +InlineClasses
inline class UInt(val a: Int) {
fun test() {
takeNullable(this) // box
takeAnyInside(this) // box
takeAnyInside(this.a) // box int
}
fun takeAnyInside(a: Any) {}
}
fun takeNullable(a: UInt?) {}
// 2 INVOKESTATIC UInt\$Erased.box
// 0 INVOKEVIRTUAL Foo.unbox
// 1 valueOf
// 0 intValue
@@ -10496,6 +10496,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
doTest(fileName);
}
@TestMetadata("useThisInsideInlineClass.kt")
public void testUseThisInsideInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useThisInsideInlineClass.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/innerNested")
@@ -10496,6 +10496,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
doTest(fileName);
}
@TestMetadata("useThisInsideInlineClass.kt")
public void testUseThisInsideInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useThisInsideInlineClass.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/innerNested")
@@ -1920,6 +1920,12 @@ public class BytecodeTextTestGenerated extends AbstractBytecodeTextTest {
doTest(fileName);
}
@TestMetadata("boxThisOfInlineClass.kt")
public void testBoxThisOfInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inlineClasses/boxThisOfInlineClass.kt");
doTest(fileName);
}
@TestMetadata("boxUnboxInlineClassFromMethodReturnType.kt")
public void testBoxUnboxInlineClassFromMethodReturnType() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeText/inlineClasses/boxUnboxInlineClassFromMethodReturnType.kt");
@@ -10496,6 +10496,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
doTest(fileName);
}
@TestMetadata("useThisInsideInlineClass.kt")
public void testUseThisInsideInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useThisInsideInlineClass.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/innerNested")
@@ -11480,6 +11480,12 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useInlineFunctionInsideInlineClass.kt");
doTest(fileName);
}
@TestMetadata("useThisInsideInlineClass.kt")
public void testUseThisInsideInlineClass() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/inlineClasses/useThisInsideInlineClass.kt");
doTest(fileName);
}
}
@TestMetadata("compiler/testData/codegen/box/innerNested")