diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/JavaClassProperty.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/JavaClassProperty.kt index 5c58f307690..992c458a6b7 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/JavaClassProperty.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/intrinsics/JavaClassProperty.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.codegen.ExpressionCodegen import org.jetbrains.kotlin.codegen.StackValue import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.resolve.jvm.AsmTypes.UNIT_TYPE import org.jetbrains.kotlin.resolve.jvm.AsmTypes.getType import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter @@ -42,7 +43,12 @@ object JavaClassProperty : IntrinsicPropertyGetter() { fun generateImpl(v: InstructionAdapter, receiver: StackValue): Type { val type = receiver.type - if (isPrimitive(type)) { + if (type == Type.VOID_TYPE) { + receiver.put(Type.VOID_TYPE, v) + StackValue.unit().put(UNIT_TYPE, v) + v.invokevirtual("java/lang/Object", "getClass", "()Ljava/lang/Class;", false) + } + else if (isPrimitive(type)) { if (!StackValue.couldSkipReceiverOnStaticCall(receiver)) { receiver.put(type, v) AsmUtil.pop(v, type) @@ -61,12 +67,7 @@ object JavaClassProperty : IntrinsicPropertyGetter() { val classType = codegen.state.typeMapper.mapType(resolvedCall.call.dispatchReceiver!!.type) return object : IntrinsicCallable(getType(Class::class.java), listOf(), classType, null) { override fun invokeIntrinsic(v: InstructionAdapter) { - if (isPrimitive(classType)) { - v.getstatic(boxType(classType).internalName, "TYPE", "Ljava/lang/Class;") - } - else { - v.invokevirtual("java/lang/Object", "getClass", "()Ljava/lang/Class;", false) - } + generateImpl(v, StackValue.none()) } override fun isStaticCall() = isPrimitive(classType) diff --git a/compiler/testData/codegen/box/callableReference/bound/localUnitFunction.kt b/compiler/testData/codegen/box/callableReference/bound/localUnitFunction.kt new file mode 100644 index 00000000000..dcb5c44738b --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/bound/localUnitFunction.kt @@ -0,0 +1,9 @@ +// TARGET_BACKEND: JVM +// WITH_RUNTIME + +fun box(): String { + fun foo(): Unit {} + assert(Unit.javaClass.equals(foo().javaClass)) + assert(Unit.javaClass.equals(foo()::class.java)) + return "OK" +} diff --git a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index 4f36c259ece..0ea5ec5aed2 100644 --- a/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-ir-jvm/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -1621,6 +1621,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes doTest(fileName); } + @TestMetadata("localUnitFunction.kt") + public void testLocalUnitFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/localUnitFunction.kt"); + doTest(fileName); + } + @TestMetadata("multiCase.kt") public void testMultiCase() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/multiCase.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 9c1dd65ce5f..8621799785e 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -1621,6 +1621,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { doTest(fileName); } + @TestMetadata("localUnitFunction.kt") + public void testLocalUnitFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/localUnitFunction.kt"); + doTest(fileName); + } + @TestMetadata("multiCase.kt") public void testMultiCase() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/multiCase.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 3c0770b43f0..d481d2483e3 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -1621,6 +1621,12 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes doTest(fileName); } + @TestMetadata("localUnitFunction.kt") + public void testLocalUnitFunction() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/localUnitFunction.kt"); + doTest(fileName); + } + @TestMetadata("multiCase.kt") public void testMultiCase() throws Exception { String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/codegen/box/callableReference/bound/multiCase.kt");