diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/CallReceiver.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/CallReceiver.java index d6370045649..b7790b125fd 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/CallReceiver.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/CallReceiver.java @@ -117,7 +117,7 @@ public class CallReceiver extends StackValue { // all the needed information, for example there's no way to find out whether or not a smart cast was applied to the receiver. if (container instanceof ClassDescriptor) { ClassDescriptor classDescriptor = (ClassDescriptor) container; - return new AsmTypeAndKotlinType(typeMapper.mapClass(classDescriptor), classDescriptor.getDefaultType()); + return new AsmTypeAndKotlinType(typeMapper.mapType(classDescriptor), classDescriptor.getDefaultType()); } KotlinType dispatchReceiverType = dispatchReceiver.getReturnType(); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java index 2aa7e0b6ede..c331a7704bc 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionCodegen.java @@ -243,7 +243,8 @@ public class FunctionCodegen { isClass(containingDeclaration) && ((ClassDescriptor) containingDeclaration).isInline() && contextKind != OwnerKind.ERASED_INLINE_CLASS && - functionDescriptor instanceof SimpleFunctionDescriptor && + !(functionDescriptor instanceof ConstructorDescriptor) && + !KotlinTypeMapper.isAccessor(functionDescriptor) && origin.getOriginKind() != JvmDeclarationOriginKind.UNBOX_METHOD_OF_INLINE_CLASS; if (isOpenSuspendInClass) { diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java index 31ec62d52a7..9dcd75aa0c2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyCodegen.java @@ -124,7 +124,8 @@ public class PropertyCodegen { @Nullable KtPropertyAccessor getter, @Nullable KtPropertyAccessor setter ) { - assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || kind == OwnerKind.DEFAULT_IMPLS + assert kind == OwnerKind.PACKAGE || kind == OwnerKind.IMPLEMENTATION || + kind == OwnerKind.DEFAULT_IMPLS || kind == OwnerKind.ERASED_INLINE_CLASS : "Generating property with a wrong kind (" + kind + "): " + descriptor; genBackingFieldAndAnnotations(declaration, descriptor, false); diff --git a/compiler/testData/codegen/box/inlineClasses/checkCallingMembersInsideInlineClass.kt b/compiler/testData/codegen/box/inlineClasses/checkCallingMembersInsideInlineClass.kt new file mode 100644 index 00000000000..804adc8ea96 --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/checkCallingMembersInsideInlineClass.kt @@ -0,0 +1,24 @@ +// !LANGUAGE: +InlineClasses + +inline class Foo(val x: Int) { + fun empty() = "" + fun withParam(a: String) = a + fun withInlineClassParam(f: Foo) = f.toString() + + fun test(): String { + val a = empty() + val b = withParam("hello") + val c = withInlineClassParam(this) + return a + b + c + } + + override fun toString(): String { + return x.toString() + } +} + +fun box(): String { + val f = Foo(12) + return if (f.test() != "hello12") "fail" else "OK" + return "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/box/inlineClasses/computablePropertyInsideInlineClass.kt b/compiler/testData/codegen/box/inlineClasses/computablePropertyInsideInlineClass.kt new file mode 100644 index 00000000000..5b121fec3ef --- /dev/null +++ b/compiler/testData/codegen/box/inlineClasses/computablePropertyInsideInlineClass.kt @@ -0,0 +1,10 @@ +// !LANGUAGE: +InlineClasses + +inline class UIntArray(private val intArray: IntArray) { + val size get() = intArray.size +} + +fun box(): String { + val array = UIntArray(intArrayOf(1, 2, 3)) + return if (array.size != 3) "fail" else "OK" +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/computablePropertiesInsideInlineClass.kt b/compiler/testData/codegen/bytecodeListing/inlineClasses/computablePropertiesInsideInlineClass.kt new file mode 100644 index 00000000000..dafa4616f9a --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/computablePropertiesInsideInlineClass.kt @@ -0,0 +1,6 @@ +// !LANGUAGE: +InlineClasses + +inline class Foo(val x: Int) { + val prop: Int get() = 1 + val asThis: Foo get() = this +} \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/computablePropertiesInsideInlineClass.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/computablePropertiesInsideInlineClass.txt new file mode 100644 index 00000000000..0c286604a0e --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/computablePropertiesInsideInlineClass.txt @@ -0,0 +1,16 @@ +@kotlin.Metadata +public final static class Foo$Erased { + public final static @org.jetbrains.annotations.NotNull method box(p0: int): Foo + public final static method getAsThis(p0: int): int + public final static method getProp(p0: int): int +} + +@kotlin.Metadata +public final class Foo { + private final field x: int + public method (p0: int): void + public final method getAsThis(): int + public final method getProp(): int + public final method getX(): int + public final method unbox(): int +} diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/shapeOfInlineClassWithPrivateConstructor.kt b/compiler/testData/codegen/bytecodeListing/inlineClasses/shapeOfInlineClassWithPrivateConstructor.kt new file mode 100644 index 00000000000..0c901e42ab3 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/shapeOfInlineClassWithPrivateConstructor.kt @@ -0,0 +1,3 @@ +// !LANGUAGE: +InlineClasses + +inline class UInt private constructor(val value: Int) \ No newline at end of file diff --git a/compiler/testData/codegen/bytecodeListing/inlineClasses/shapeOfInlineClassWithPrivateConstructor.txt b/compiler/testData/codegen/bytecodeListing/inlineClasses/shapeOfInlineClassWithPrivateConstructor.txt new file mode 100644 index 00000000000..3ea2e039690 --- /dev/null +++ b/compiler/testData/codegen/bytecodeListing/inlineClasses/shapeOfInlineClassWithPrivateConstructor.txt @@ -0,0 +1,12 @@ +@kotlin.Metadata +public final static class UInt$Erased { + public final static @org.jetbrains.annotations.NotNull method box(p0: int): UInt +} + +@kotlin.Metadata +public final class UInt { + private final field value: int + private method (p0: int): void + public final method getValue(): int + public final method unbox(): int +} diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java index f974bb05ad4..0f0491ac20b 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BytecodeListingTestGenerated.java @@ -273,6 +273,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { doTest(fileName); } + @TestMetadata("computablePropertiesInsideInlineClass.kt") + public void testComputablePropertiesInsideInlineClass() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/inlineClasses/computablePropertiesInsideInlineClass.kt"); + doTest(fileName); + } + @TestMetadata("noBridgesForErasedInlineClass.kt") public void testNoBridgesForErasedInlineClass() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/inlineClasses/noBridgesForErasedInlineClass.kt"); @@ -284,6 +290,12 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/inlineClasses/shapeOfInlineClassWithPrimitive.kt"); doTest(fileName); } + + @TestMetadata("shapeOfInlineClassWithPrivateConstructor.kt") + public void testShapeOfInlineClassWithPrivateConstructor() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/bytecodeListing/inlineClasses/shapeOfInlineClassWithPrivateConstructor.kt"); + doTest(fileName); + } } @TestMetadata("compiler/testData/codegen/bytecodeListing/specialBridges")