diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java index 53affdcac67..d0db09728b8 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirBlackBoxCodegenTestGenerated.java @@ -16492,6 +16492,12 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT runTest("compiler/testData/codegen/box/funInterface/kt46512_indyFunInterfaceOverCallableReference.kt"); } + @Test + @TestMetadata("kt46908_functionSupertype.kt") + public void testKt46908_functionSupertype() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt"); + } + @Test @TestMetadata("multimodule.kt") public void testMultimodule() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index c9c16d172d6..b577b36c16d 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -2089,6 +2089,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/expressions/funInterface/castFromAny.kt"); } + @Test + @TestMetadata("functionSupertype.kt") + public void testFunctionSupertype() throws Exception { + runTest("compiler/testData/ir/irText/expressions/funInterface/functionSupertype.kt"); + } + @Test @TestMetadata("partialSam.kt") public void testPartialSam() throws Exception { diff --git a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt index 6d47438c2fb..cd04fb13c26 100644 --- a/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt +++ b/compiler/ir/ir.psi2ir/src/org/jetbrains/kotlin/psi2ir/generators/ArgumentsGenerationUtils.kt @@ -17,7 +17,7 @@ package org.jetbrains.kotlin.psi2ir.generators import org.jetbrains.kotlin.builtins.isBuiltinFunctionalType -import org.jetbrains.kotlin.builtins.isFunctionTypeOrSubtype +import org.jetbrains.kotlin.builtins.isFunctionType import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.impl.SyntheticFieldDescriptor @@ -585,7 +585,7 @@ fun StatementGenerator.generateSamConversionForValueArgumentsIfRequired(call: Ca if (!samConversion.isSamType(underlyingValueParameter.type) && !samConversion.isSamType(underlyingValueParameter.original.type) ) continue - if (!originalValueParameters[i].type.isFunctionTypeOrSubtype) continue + if (!originalValueParameters[i].type.isFunctionType) continue } val samKotlinType = getSamTypeForValueParameter(underlyingValueParameter) diff --git a/compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt b/compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt new file mode 100644 index 00000000000..77902590af0 --- /dev/null +++ b/compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt @@ -0,0 +1,18 @@ +// IGNORE_BACKEND: JS, JS_IR, WASM + +fun interface Foo : () -> Int + +fun id(foo: Foo): Any = foo + +fun box(): String { + val p1 = object : Foo { + override fun invoke(): Int = 42 + override fun toString(): String = "OK" + } + val p2 = id(p1) + + if (p1 !== p2) return "Fail identity equals" + if (p1.toString() != p2.toString()) return "Fail toString" + + return p2.toString() +} diff --git a/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.fir.kt.txt b/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.fir.kt.txt new file mode 100644 index 00000000000..63837891b5a --- /dev/null +++ b/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.fir.kt.txt @@ -0,0 +1,11 @@ +fun interface Foo : Function0 { + +} + +fun id(foo: Foo): Any { + return foo +} + +fun test(foo: Foo) { + id(foo = foo) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.fir.txt b/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.fir.txt new file mode 100644 index 00000000000..c991b851c84 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.fir.txt @@ -0,0 +1,31 @@ +FILE fqName: fileName:/functionSupertype.kt + CLASS INTERFACE name:Foo modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Function0] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Foo + FUN FAKE_OVERRIDE name:invoke visibility:public modality:ABSTRACT <> ($this:kotlin.Function0) returnType:kotlin.Int [fake_override,operator] + overridden: + public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0 + $this: VALUE_PARAMETER name: type:kotlin.Function0 + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in kotlin.Function0 + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.Function0 + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in kotlin.Function0 + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:id visibility:public modality:FINAL <> (foo:.Foo) returnType:kotlin.Any + VALUE_PARAMETER name:foo index:0 type:.Foo + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun id (foo: .Foo): kotlin.Any declared in ' + GET_VAR 'foo: .Foo declared in .id' type=.Foo origin=null + FUN name:test visibility:public modality:FINAL <> (foo:.Foo) returnType:kotlin.Unit + VALUE_PARAMETER name:foo index:0 type:.Foo + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun id (foo: .Foo): kotlin.Any declared in ' type=kotlin.Any origin=null + foo: GET_VAR 'foo: .Foo declared in .test' type=.Foo origin=null diff --git a/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.kt b/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.kt new file mode 100644 index 00000000000..92850216bba --- /dev/null +++ b/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.kt @@ -0,0 +1,9 @@ +// IGNORE_BACKEND: JS_IR + +fun interface Foo : () -> Int + +fun id(foo: Foo): Any = foo + +fun test(foo: Foo) { + id(foo) +} diff --git a/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.kt.txt b/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.kt.txt new file mode 100644 index 00000000000..63837891b5a --- /dev/null +++ b/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.kt.txt @@ -0,0 +1,11 @@ +fun interface Foo : Function0 { + +} + +fun id(foo: Foo): Any { + return foo +} + +fun test(foo: Foo) { + id(foo = foo) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.txt b/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.txt new file mode 100644 index 00000000000..40d60b55b0f --- /dev/null +++ b/compiler/testData/ir/irText/expressions/funInterface/functionSupertype.txt @@ -0,0 +1,31 @@ +FILE fqName: fileName:/functionSupertype.kt + CLASS INTERFACE name:Foo modality:ABSTRACT visibility:public [fun] superTypes:[kotlin.Function0] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Foo + FUN FAKE_OVERRIDE name:invoke visibility:public modality:ABSTRACT <> ($this:kotlin.Function0) returnType:kotlin.Int [fake_override,operator] + overridden: + public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0 + $this: VALUE_PARAMETER name: type:kotlin.Function0 + FUN FAKE_OVERRIDE name:equals visibility:public modality:OPEN <> ($this:kotlin.Any, other:kotlin.Any?) returnType:kotlin.Boolean [fake_override,operator] + overridden: + public open fun equals (other: kotlin.Any?): kotlin.Boolean [fake_override,operator] declared in kotlin.Function0 + $this: VALUE_PARAMETER name: type:kotlin.Any + VALUE_PARAMETER name:other index:0 type:kotlin.Any? + FUN FAKE_OVERRIDE name:hashCode visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.Int [fake_override] + overridden: + public open fun hashCode (): kotlin.Int [fake_override] declared in kotlin.Function0 + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN FAKE_OVERRIDE name:toString visibility:public modality:OPEN <> ($this:kotlin.Any) returnType:kotlin.String [fake_override] + overridden: + public open fun toString (): kotlin.String [fake_override] declared in kotlin.Function0 + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:id visibility:public modality:FINAL <> (foo:.Foo) returnType:kotlin.Any + VALUE_PARAMETER name:foo index:0 type:.Foo + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun id (foo: .Foo): kotlin.Any declared in ' + GET_VAR 'foo: .Foo declared in .id' type=.Foo origin=null + FUN name:test visibility:public modality:FINAL <> (foo:.Foo) returnType:kotlin.Unit + VALUE_PARAMETER name:foo index:0 type:.Foo + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public final fun id (foo: .Foo): kotlin.Any declared in ' type=kotlin.Any origin=null + foo: GET_VAR 'foo: .Foo declared in .test' type=.Foo origin=null diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java index f6af8169730..2e320f53297 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/BlackBoxCodegenTestGenerated.java @@ -16372,6 +16372,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/funInterface/kt46512_indyFunInterfaceOverCallableReference.kt"); } + @Test + @TestMetadata("kt46908_functionSupertype.kt") + public void testKt46908_functionSupertype() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt"); + } + @Test @TestMetadata("multimodule.kt") public void testMultimodule() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java index f32cffe0471..d5ae1fb6828 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenTestGenerated.java @@ -16492,6 +16492,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/funInterface/kt46512_indyFunInterfaceOverCallableReference.kt"); } + @Test + @TestMetadata("kt46908_functionSupertype.kt") + public void testKt46908_functionSupertype() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt"); + } + @Test @TestMetadata("multimodule.kt") public void testMultimodule() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index 6dca937df61..f2d2f96b6df 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -2089,6 +2089,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/expressions/funInterface/castFromAny.kt"); } + @Test + @TestMetadata("functionSupertype.kt") + public void testFunctionSupertype() throws Exception { + runTest("compiler/testData/ir/irText/expressions/funInterface/functionSupertype.kt"); + } + @Test @TestMetadata("partialSam.kt") public void testPartialSam() throws Exception { diff --git a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java index 96099ce444f..907ea2ee12d 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -13511,6 +13511,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/funInterface/kt46512_indyFunInterfaceOverCallableReference.kt"); } + @TestMetadata("kt46908_functionSupertype.kt") + public void testKt46908_functionSupertype() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt"); + } + @TestMetadata("multimodule.kt") public void testMultimodule() throws Exception { runTest("compiler/testData/codegen/box/funInterface/multimodule.kt"); diff --git a/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java index ed7dc3f30bc..d092cb3b5de 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java @@ -1636,6 +1636,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase { runTest("compiler/testData/ir/irText/expressions/funInterface/castFromAny.kt"); } + @TestMetadata("functionSupertype.kt") + public void testFunctionSupertype() throws Exception { + runTest("compiler/testData/ir/irText/expressions/funInterface/functionSupertype.kt"); + } + @TestMetadata("partialSam.kt") public void testPartialSam() throws Exception { runTest("compiler/testData/ir/irText/expressions/funInterface/partialSam.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java index 06659fa26c3..b55b328b990 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/es6/semantics/IrJsCodegenBoxES6TestGenerated.java @@ -11905,6 +11905,11 @@ public class IrJsCodegenBoxES6TestGenerated extends AbstractIrJsCodegenBoxES6Tes runTest("compiler/testData/codegen/box/funInterface/kt46512_indyFunInterfaceOverCallableReference.kt"); } + @TestMetadata("kt46908_functionSupertype.kt") + public void testKt46908_functionSupertype() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt"); + } + @TestMetadata("multimodule.kt") public void testMultimodule() throws Exception { runTest("compiler/testData/codegen/box/funInterface/multimodule.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java index 03348dac180..2964536e060 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsCodegenBoxTestGenerated.java @@ -11311,6 +11311,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest { runTest("compiler/testData/codegen/box/funInterface/kt46512_indyFunInterfaceOverCallableReference.kt"); } + @TestMetadata("kt46908_functionSupertype.kt") + public void testKt46908_functionSupertype() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt"); + } + @TestMetadata("multimodule.kt") public void testMultimodule() throws Exception { runTest("compiler/testData/codegen/box/funInterface/multimodule.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java index 54ddd6ecbfa..4c5735b6abb 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/semantics/JsCodegenBoxTestGenerated.java @@ -11276,6 +11276,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest { runTest("compiler/testData/codegen/box/funInterface/kt46512_indyFunInterfaceOverCallableReference.kt"); } + @TestMetadata("kt46908_functionSupertype.kt") + public void testKt46908_functionSupertype() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt"); + } + @TestMetadata("multimodule.kt") public void testMultimodule() throws Exception { runTest("compiler/testData/codegen/box/funInterface/multimodule.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java index 7a43e61ad60..9564a3fd2d8 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/wasm/semantics/IrCodegenBoxWasmTestGenerated.java @@ -6640,6 +6640,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest runTest("compiler/testData/codegen/box/funInterface/kt46512_indyFunInterfaceOverCallableReference.kt"); } + @TestMetadata("kt46908_functionSupertype.kt") + public void testKt46908_functionSupertype() throws Exception { + runTest("compiler/testData/codegen/box/funInterface/kt46908_functionSupertype.kt"); + } + @TestMetadata("compiler/testData/codegen/box/funInterface/equality") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class)