diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt index 09fec52ef76..debb711f625 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/SamResolution.kt @@ -34,7 +34,7 @@ import org.jetbrains.kotlin.types.Variance interface FirSamResolver : FirSessionComponent { fun getFunctionTypeForPossibleSamType(type: ConeKotlinType): ConeKotlinType? - fun shouldRunSamConversionForFunction(firNamedFunction: FirSimpleFunction): Boolean + fun shouldRunSamConversionForFunction(firFunction: FirFunction<*>): Boolean fun getSamConstructor(firRegularClass: FirRegularClass): FirSimpleFunction? } @@ -202,7 +202,7 @@ class FirSamResolverImpl( } as? ConeKotlinType } - override fun shouldRunSamConversionForFunction(firNamedFunction: FirSimpleFunction): Boolean { + override fun shouldRunSamConversionForFunction(firFunction: FirFunction<*>): Boolean { // TODO: properly support, see org.jetbrains.kotlin.load.java.sam.JvmSamConversionTransformer.shouldRunSamConversionForFunction return true } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt index e731baf8bb6..067a27a498a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Arguments.kt @@ -7,7 +7,7 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirAnonymousFunction -import org.jetbrains.kotlin.fir.declarations.FirSimpleFunction +import org.jetbrains.kotlin.fir.declarations.FirFunction import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.expressions.* import org.jetbrains.kotlin.fir.inferenceContext @@ -305,8 +305,8 @@ private fun Candidate.getExpectedTypeWithSAMConversion( ): ConeKotlinType? { if (candidateExpectedType.isBuiltinFunctionalType(session)) return null // TODO: if (!callComponents.languageVersionSettings.supportsFeature(LanguageFeature.SamConversionPerArgument)) return null - val firNamedFunction = symbol.fir as? FirSimpleFunction ?: return null - if (!samResolver.shouldRunSamConversionForFunction(firNamedFunction)) return null + val firFunction = symbol.fir as? FirFunction<*> ?: return null + if (!samResolver.shouldRunSamConversionForFunction(firFunction)) return null val argumentIsFunctional = when ((argument as? FirWrappedArgumentExpression)?.expression ?: argument) { is FirAnonymousFunction, is FirCallableReferenceAccess -> true diff --git a/compiler/fir/resolve/testData/resolve/problems/samConversionInConstructorCall.txt b/compiler/fir/resolve/testData/resolve/problems/samConversionInConstructorCall.txt deleted file mode 100644 index 2f51641ad66..00000000000 --- a/compiler/fir/resolve/testData/resolve/problems/samConversionInConstructorCall.txt +++ /dev/null @@ -1,7 +0,0 @@ -FILE: main.kt - public final fun test(): R|kotlin/Unit| { - #( = Foo@fun (): R|ERROR CLASS: Unresolved name: it| { - ^ # - } - ) - } diff --git a/compiler/fir/resolve/testData/resolve/problems/samConversionInConstructorCall.kt b/compiler/fir/resolve/testData/resolve/samConversions/samConversionInConstructorCall.kt similarity index 73% rename from compiler/fir/resolve/testData/resolve/problems/samConversionInConstructorCall.kt rename to compiler/fir/resolve/testData/resolve/samConversions/samConversionInConstructorCall.kt index d69a4ea4181..5702cc7cf0b 100644 --- a/compiler/fir/resolve/testData/resolve/problems/samConversionInConstructorCall.kt +++ b/compiler/fir/resolve/testData/resolve/samConversions/samConversionInConstructorCall.kt @@ -13,5 +13,5 @@ public class Foo { // FILE: main.kt fun test() { - Foo { it } + Foo { it } } diff --git a/compiler/fir/resolve/testData/resolve/samConversions/samConversionInConstructorCall.txt b/compiler/fir/resolve/testData/resolve/samConversions/samConversionInConstructorCall.txt new file mode 100644 index 00000000000..04104457da1 --- /dev/null +++ b/compiler/fir/resolve/testData/resolve/samConversions/samConversionInConstructorCall.txt @@ -0,0 +1,7 @@ +FILE: main.kt + public final fun test(): R|kotlin/Unit| { + R|/Foo.Foo|( = Foo@fun (it: R|kotlin/Boolean|): R|kotlin/Boolean| { + ^ R|/it| + } + ) + } diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java index 73a2efb15df..813c67fd18a 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsTestGenerated.java @@ -1176,11 +1176,6 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/problems/propertyFromJavaPlusAssign.kt"); } - @TestMetadata("samConversionInConstructorCall.kt") - public void testSamConversionInConstructorCall() throws Exception { - runTest("compiler/fir/resolve/testData/resolve/problems/samConversionInConstructorCall.kt"); - } - @TestMetadata("syntheticsVsNormalProperties.kt") public void testSyntheticsVsNormalProperties() throws Exception { runTest("compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.kt"); @@ -1285,6 +1280,11 @@ public class FirDiagnosticsTestGenerated extends AbstractFirDiagnosticsTest { runTest("compiler/fir/resolve/testData/resolve/samConversions/runnable.kt"); } + @TestMetadata("samConversionInConstructorCall.kt") + public void testSamConversionInConstructorCall() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/samConversions/samConversionInConstructorCall.kt"); + } + @TestMetadata("samSupertype.kt") public void testSamSupertype() throws Exception { runTest("compiler/fir/resolve/testData/resolve/samConversions/samSupertype.kt"); diff --git a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java index ff89f666770..f08d5fc3a2e 100644 --- a/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java +++ b/compiler/fir/resolve/tests/org/jetbrains/kotlin/fir/FirDiagnosticsWithLightTreeTestGenerated.java @@ -1176,11 +1176,6 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/resolve/testData/resolve/problems/propertyFromJavaPlusAssign.kt"); } - @TestMetadata("samConversionInConstructorCall.kt") - public void testSamConversionInConstructorCall() throws Exception { - runTest("compiler/fir/resolve/testData/resolve/problems/samConversionInConstructorCall.kt"); - } - @TestMetadata("syntheticsVsNormalProperties.kt") public void testSyntheticsVsNormalProperties() throws Exception { runTest("compiler/fir/resolve/testData/resolve/problems/syntheticsVsNormalProperties.kt"); @@ -1285,6 +1280,11 @@ public class FirDiagnosticsWithLightTreeTestGenerated extends AbstractFirDiagnos runTest("compiler/fir/resolve/testData/resolve/samConversions/runnable.kt"); } + @TestMetadata("samConversionInConstructorCall.kt") + public void testSamConversionInConstructorCall() throws Exception { + runTest("compiler/fir/resolve/testData/resolve/samConversions/samConversionInConstructorCall.kt"); + } + @TestMetadata("samSupertype.kt") public void testSamSupertype() throws Exception { runTest("compiler/fir/resolve/testData/resolve/samConversions/samSupertype.kt"); diff --git a/compiler/testData/diagnostics/tests/j+k/samInConstructorWithGenerics.fir.kt b/compiler/testData/diagnostics/tests/j+k/samInConstructorWithGenerics.fir.kt index f5a5200958b..b8695fc6aaa 100644 --- a/compiler/testData/diagnostics/tests/j+k/samInConstructorWithGenerics.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/samInConstructorWithGenerics.fir.kt @@ -18,6 +18,6 @@ public class Observable { import j.* -class K : Observable({}) +class K : Observable({}) class J : Observable(null) diff --git a/compiler/testData/diagnostics/tests/j+k/typeAliasWithSamConstructor.fir.kt b/compiler/testData/diagnostics/tests/j+k/typeAliasWithSamConstructor.fir.kt index 808122807cf..ab708f9a374 100644 --- a/compiler/testData/diagnostics/tests/j+k/typeAliasWithSamConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/j+k/typeAliasWithSamConstructor.fir.kt @@ -14,5 +14,5 @@ public class Observable { typealias ObservableAlias = Observable typealias ObservableIntAlias = Observable -class A : ObservableAlias({}) -class B : ObservableIntAlias({}) +class A : ObservableAlias({}) +class B : ObservableIntAlias({}) diff --git a/compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterConstructor.fir.kt b/compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterConstructor.fir.kt index be0da77be10..0394f4ee7d6 100644 --- a/compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/namedArguments/disallowForSamAdapterConstructor.fir.kt @@ -13,5 +13,5 @@ public class J { package test fun test() { - J("", r = { }, z = false) + J("", r = { }, z = false) } diff --git a/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.fir.kt b/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.fir.kt index d3e7f0f3441..6918bd69c88 100644 --- a/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.fir.kt +++ b/compiler/testData/diagnostics/tests/platformTypes/samAdapterInConstructor.fir.kt @@ -10,5 +10,5 @@ public class A { // FILE: main.kt fun foo() { - val result: A = A { x, y -> 1 } + val result: A = A { x, y -> 1 } } diff --git a/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgument.fir.kt b/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgument.fir.kt index 1840c3a698e..ac380628de6 100644 --- a/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgument.fir.kt +++ b/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgument.fir.kt @@ -36,10 +36,10 @@ fun main(x2: Runnable) { Test.foo1(x2, *arrayOf("")) val i1 = Test({}, arrayOf()) - val i2 = Test({}, *arrayOf()) + val i2 = Test({}, *arrayOf()) val i3 = Test({}, x3) val i4 = Test({}, arrayOf("")) - val i5 = Test({}, {}, *arrayOf("")) + val i5 = Test({}, {}, *arrayOf("")) val i6 = Test({}, {}, arrayOf()) i1.foo2({}, {}, arrayOf()) diff --git a/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgumentProhibited.fir.kt b/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgumentProhibited.fir.kt index 8f6b82eb2a6..3f1734f84b8 100644 --- a/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgumentProhibited.fir.kt +++ b/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgumentProhibited.fir.kt @@ -36,19 +36,19 @@ fun main(x2: Runnable) { Test.foo1(x2, *arrayOf("")) val i1 = Test({}, arrayOf()) - val i2 = Test({}, *arrayOf()) + val i2 = Test({}, *arrayOf()) val i3 = Test({}, x3) val i4 = Test({}, arrayOf("")) - val i5 = Test({}, {}, *arrayOf("")) + val i5 = Test({}, {}, *arrayOf("")) val i6 = Test({}, {}, arrayOf()) - i2.foo2({}, {}, arrayOf()) - i2.foo2({}, {}, *arrayOf()) - i2.foo2({}, x2, arrayOf()) - i2.foo2(x2, {}, *arrayOf()) + i2.foo2({}, {}, arrayOf()) + i2.foo2({}, {}, *arrayOf()) + i2.foo2({}, x2, arrayOf()) + i2.foo2(x2, {}, *arrayOf()) - i2.foo2({}, {}, arrayOf("")) - i2.foo2({}, {}, *x3) - i2.foo2({}, x2, x3) - i2.foo2(x2, {}, *arrayOf("")) -} \ No newline at end of file + i2.foo2({}, {}, arrayOf("")) + i2.foo2({}, {}, *x3) + i2.foo2({}, x2, x3) + i2.foo2(x2, {}, *arrayOf("")) +} diff --git a/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgumentWithoutSamConversionsPerArgument.fir.kt b/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgumentWithoutSamConversionsPerArgument.fir.kt index 58d1db59595..3269154b551 100644 --- a/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgumentWithoutSamConversionsPerArgument.fir.kt +++ b/compiler/testData/diagnostics/tests/samConversions/arrayAsVarargAfterSamArgumentWithoutSamConversionsPerArgument.fir.kt @@ -36,10 +36,10 @@ fun main(x2: Runnable) { Test.foo1(x2, *arrayOf("")) val i1 = Test({}, arrayOf()) - val i2 = Test({}, *arrayOf()) + val i2 = Test({}, *arrayOf()) val i3 = Test({}, x3) val i4 = Test({}, arrayOf("")) - val i5 = Test({}, {}, *arrayOf("")) + val i5 = Test({}, {}, *arrayOf("")) val i6 = Test({}, {}, arrayOf()) i1.foo2({}, {}, arrayOf()) @@ -51,4 +51,4 @@ fun main(x2: Runnable) { i1.foo2({}, {}, *x3) i1.foo2({}, x2, x3) i1.foo2(x2, {}, *arrayOf("")) -} \ No newline at end of file +} diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.txt b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.txt index becad73bfcc..677a0c7b43e 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.txt @@ -1,14 +1,17 @@ FILE fqName: fileName:/samConversionInGenericConstructorCall.kt - FUN name:test1 visibility:public modality:FINAL <> (f:kotlin.Function1) returnType:IrErrorType + FUN name:test1 visibility:public modality:FINAL <> (f:kotlin.Function1) returnType:.C VALUE_PARAMETER name:f index:0 type:kotlin.Function1 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun test1 (f: kotlin.Function1): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - GET_VAR 'f: kotlin.Function1 declared in .test1' type=kotlin.Function1 origin=null + RETURN type=kotlin.Nothing from='public final fun test1 (f: kotlin.Function1): .C declared in ' + CONSTRUCTOR_CALL 'public constructor (jxx: .J?, X of ?>?) declared in .C' type=.C origin=null + : kotlin.String? + jxx: GET_VAR 'f: kotlin.Function1 declared in .test1' type=kotlin.Function1 origin=null FUN name:test2 visibility:public modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Unit VALUE_PARAMETER name:x index:0 type:kotlin.Any BLOCK_BODY TYPE_OP type=kotlin.Function1 origin=CAST typeOperand=kotlin.Function1 GET_VAR 'x: kotlin.Any declared in .test2' type=kotlin.Any origin=null - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - GET_VAR 'x: kotlin.Any declared in .test2' type=kotlin.Function1 origin=null + CONSTRUCTOR_CALL 'public constructor (jxx: .J?, X of ?>?) declared in .C' type=.C origin=null + : kotlin.String? + jxx: TYPE_OP type=kotlin.Function1 origin=IMPLICIT_CAST typeOperand=kotlin.Function1 + GET_VAR 'x: kotlin.Any declared in .test2' type=kotlin.Any origin=null diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall_NI.fir.txt b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall_NI.fir.txt index 5dab98178af..1b89ad1f9e9 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall_NI.fir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall_NI.fir.txt @@ -4,7 +4,7 @@ FILE fqName: fileName:/samConversionInGenericConstructorCall_NI.kt VALUE_PARAMETER name:f2 index:1 type:kotlin.Function1 BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test3 (f1: kotlin.Function1, f2: kotlin.Function1): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'f2: kotlin.Function1 declared in .test3' type=kotlin.Function1 origin=null CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any] $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Outer.Outer> @@ -75,18 +75,16 @@ FILE fqName: fileName:/samConversionInGenericConstructorCall_NI.kt VALUE_PARAMETER name:g index:1 type:kotlin.Function1 BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun test4 (f: kotlin.Function1, g: kotlin.Function1): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType + ERROR_CALL 'Unresolved reference: #' type=IrErrorType GET_VAR 'g: kotlin.Function1 declared in .test4' type=kotlin.Function1 origin=null - FUN name:testGenericJavaCtor1 visibility:public modality:FINAL <> (f:kotlin.Function1) returnType:IrErrorType + FUN name:testGenericJavaCtor1 visibility:public modality:FINAL <> (f:kotlin.Function1) returnType:.G VALUE_PARAMETER name:f index:0 type:kotlin.Function1 BLOCK_BODY - RETURN type=kotlin.Nothing from='public final fun testGenericJavaCtor1 (f: kotlin.Function1): IrErrorType declared in ' - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - GET_VAR 'f: kotlin.Function1 declared in .testGenericJavaCtor1' type=kotlin.Function1 origin=null + RETURN type=kotlin.Nothing from='public final fun testGenericJavaCtor1 (f: kotlin.Function1): .G declared in ' + ERROR_EXPR 'Cannot bind 2 type arguments to ??? call with 1 type parameters' type=.G FUN name:testGenericJavaCtor2 visibility:public modality:FINAL <> (x:kotlin.Any) returnType:kotlin.Unit VALUE_PARAMETER name:x index:0 type:kotlin.Any BLOCK_BODY TYPE_OP type=kotlin.Function1 origin=CAST typeOperand=kotlin.Function1 GET_VAR 'x: kotlin.Any declared in .testGenericJavaCtor2' type=kotlin.Any origin=null - ERROR_CALL 'Unresolved reference: #' type=IrErrorType - GET_VAR 'x: kotlin.Any declared in .testGenericJavaCtor2' type=kotlin.Function1 origin=null + ERROR_EXPR 'Cannot bind 2 type arguments to ??? call with 1 type parameters' type=.G