diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java index 7578a99ab5a..953e1e66dfb 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/FunctionReferenceGenerationStrategy.java @@ -189,7 +189,9 @@ public class FunctionReferenceGenerationStrategy extends FunctionGenerationStrat result = codegen.generateNewArray(fakeExpression, referencedFunction.getReturnType(), fakeResolvedCall); } else { - result = codegen.generateConstructorCall(fakeResolvedCall, returnType); + //noinspection ConstantConditions + Type constructedType = codegen.typeMapper.mapTypeAsDeclaration(referencedFunction.getReturnType()); + result = codegen.generateConstructorCall(fakeResolvedCall, constructedType); } } else { diff --git a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java index 3e4a4e1bfc2..8b018dcf8d6 100644 --- a/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests/org/jetbrains/kotlin/codegen/ir/FirBlackBoxCodegenTestGenerated.java @@ -1973,6 +1973,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/callableReference/classesAreSynthetic.kt"); } + @TestMetadata("kt37604.kt") + public void testKt37604() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/kt37604.kt"); + } + @TestMetadata("nested.kt") public void testNested() throws Exception { runTest("compiler/testData/codegen/box/callableReference/nested.kt"); diff --git a/compiler/testData/codegen/box/callableReference/kt37604.kt b/compiler/testData/codegen/box/callableReference/kt37604.kt new file mode 100644 index 00000000000..ae7275bb81a --- /dev/null +++ b/compiler/testData/codegen/box/callableReference/kt37604.kt @@ -0,0 +1,42 @@ +// IGNORE_BACKEND_FIR: JVM_IR + +fun useUnit(fn: () -> Unit) { + fn.invoke() +} + +var cInit = false + +class C { + init { + cInit = true + } +} + +var cWithDefaultInit = false + +class CWithDefault(x: Int = 1) { + init { + cWithDefaultInit = true + } +} + +var cWithVarargInit = false + +class CWithVararg(vararg x: Int) { + init { + cWithVarargInit = true + } +} + +fun box(): String { + useUnit(::C) + if (!cInit) throw AssertionError("cInit") + + useUnit(::CWithDefault) + if (!cWithDefaultInit) throw AssertionError("cWithDefaultInit") + + useUnit(::CWithVararg) + if (!cWithVarargInit) throw AssertionError("cWithVarargInit") + + return "OK" +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java index 8faabe61189..e71dbdafc5f 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/BlackBoxCodegenTestGenerated.java @@ -1993,6 +1993,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/callableReference/classesAreSynthetic.kt"); } + @TestMetadata("kt37604.kt") + public void testKt37604() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/kt37604.kt"); + } + @TestMetadata("nested.kt") public void testNested() throws Exception { runTest("compiler/testData/codegen/box/callableReference/nested.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 41962901bdc..48d7849fbd0 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -1993,6 +1993,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/callableReference/classesAreSynthetic.kt"); } + @TestMetadata("kt37604.kt") + public void testKt37604() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/kt37604.kt"); + } + @TestMetadata("nested.kt") public void testNested() throws Exception { runTest("compiler/testData/codegen/box/callableReference/nested.kt"); diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java index d4856904d0f..a41e355dc45 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/ir/IrBlackBoxCodegenTestGenerated.java @@ -1973,6 +1973,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/callableReference/classesAreSynthetic.kt"); } + @TestMetadata("kt37604.kt") + public void testKt37604() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/kt37604.kt"); + } + @TestMetadata("nested.kt") public void testNested() throws Exception { runTest("compiler/testData/codegen/box/callableReference/nested.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 8663af21de5..909cd038d44 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -1423,6 +1423,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @TestMetadata("kt37604.kt") + public void testKt37604() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/kt37604.kt"); + } + @TestMetadata("nested.kt") public void testNested() throws Exception { runTest("compiler/testData/codegen/box/callableReference/nested.kt"); diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 529d183c8b1..1d89ed0970c 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -1423,6 +1423,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/box/callableReference"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true); } + @TestMetadata("kt37604.kt") + public void testKt37604() throws Exception { + runTest("compiler/testData/codegen/box/callableReference/kt37604.kt"); + } + @TestMetadata("nested.kt") public void testNested() throws Exception { runTest("compiler/testData/codegen/box/callableReference/nested.kt");