From dd1d36816ba4439af275d81a48c7ef1b6aed0711 Mon Sep 17 00:00:00 2001 From: Kirill Rakhman Date: Wed, 15 Nov 2023 12:24:31 +0100 Subject: [PATCH] [FIR] Insert SAM conversion expressions during completion #KT-62847 Fixed --- .../lambdaAsSAMInterfaceWithAnnotation.txt | 10 +- .../lazyResolve/lambdaAsSAMInterface.txt | 8 +- .../lambdaAsSAMInterfaceScript.txt | 9 +- ...LFirBlackBoxCodegenBasedTestGenerated.java | 6 + ...rsedBlackBoxCodegenBasedTestGenerated.java | 6 + .../resolve/inference/javaCollector.fir.txt | 4 +- .../testData/resolve/rawTypeSam.fir.txt | 4 +- .../resolve/samConversions/genericSam.fir.txt | 16 +-- .../resolve/samConversions/kotlinSam.fir.txt | 12 +- .../samConversions/nothingVararg.fir.txt | 4 +- .../resolve/samConversions/runnable.fir.txt | 8 +- .../samConversionInConstructorCall.fir.txt | 4 +- .../samConversions/samSupertype.fir.txt | 10 +- .../samSupertypeWithOverride.fir.txt | 10 +- .../samConversions/samVsLambda.fir.txt | 4 +- .../samConversions/samWithEquals.fir.txt | 4 +- .../resolve/samConversions/simple.fir.txt | 10 +- .../referenceToJavaStdlib.fir.txt | 2 +- .../callableReferences/sam.fir.txt | 2 +- .../hashTableWithForEach.fir.txt | 4 +- .../resolveWithStdlib/j+k/MapCompute.fir.txt | 4 +- .../resolveWithStdlib/j+k/MyMap.fir.txt | 8 +- .../j+k/SyntheticWithForEach.fir.txt | 4 +- .../resolveWithStdlib/j+k/mapMerge.fir.txt | 4 +- .../problems/isAncestor.fir.txt | 4 +- .../resolveWithStdlib/removeIf.fir.txt | 4 +- .../samForComparator.fir.txt | 4 +- .../typeAliasWithForEach.fir.txt | 4 +- .../kotlin/fir/backend/Fir2IrVisitor.kt | 4 + .../backend/generators/AdapterGenerator.kt | 98 ++------------- .../generators/CallAndReferenceGenerator.kt | 4 +- ...LightTreeBlackBoxCodegenTestGenerated.java | 6 + ...hIrFakeOverrideGeneratorTestGenerated.java | 6 + .../FirPsiBlackBoxCodegenTestGenerated.java | 6 + .../kotlin/fir/resolve/calls/Arguments.kt | 39 ++++-- .../kotlin/fir/resolve/calls/Candidate.kt | 3 +- ...rCallCompletionResultsWriterTransformer.kt | 85 ++++++++++--- .../FirExpressionsResolveTransformer.kt | 41 +++++-- .../org/jetbrains/kotlin/KtSourceElement.kt | 3 + .../codegen/box/sam/kt54600.fir.ir.txt | 4 +- .../box/sam/noConversionFromSamToSam.kt | 21 ++++ .../sam/genericSamProjectedOut.fir.ir.txt | 10 +- .../sam/genericSamProjectedOut.fir.kt.txt | 10 +- .../sam/genericSamSmartcast.fir.ir.txt | 2 +- .../sam/genericSamSmartcast.fir.kt.txt | 3 +- .../sam/samByProjectedType.fir.ir.txt | 11 ++ .../sam/samByProjectedType.fir.kt.txt | 6 + .../expressions/sam/samByProjectedType.kt | 1 - ...versionInGenericConstructorCall.fir.ir.txt | 114 ++++++++++++++++++ ...versionInGenericConstructorCall.fir.kt.txt | 42 +++++++ .../samConversionInGenericConstructorCall.kt | 1 - ...mConversionInGenericConstructorCall.kt.txt | 1 + .../sam/samConversionToGeneric.fir.ir.txt | 12 +- .../sam/samConversionToGeneric.fir.kt.txt | 12 +- .../expressions/sam/samConversions.fir.ir.txt | 54 +++++++++ .../expressions/sam/samConversions.fir.kt.txt | 29 +++++ .../irText/expressions/sam/samConversions.kt | 1 - .../expressions/sam/samConversions.kt.txt | 1 + .../samConversionsWithSmartCasts.fir.ir.txt | 8 +- .../samConversionsWithSmartCasts.fir.kt.txt | 9 +- .../expressions/sam/samOperators.fir.ir.txt | 20 +-- .../expressions/sam/samOperators.fir.kt.txt | 12 +- .../ir/irText/firProblems/kt19251.fir.ir.txt | 2 +- .../ir/irText/firProblems/kt19251.fir.kt.txt | 2 +- .../codegen/BlackBoxCodegenTestGenerated.java | 6 + .../IrBlackBoxCodegenTestGenerated.java | 6 + ...kBoxCodegenWithIrInlinerTestGenerated.java | 6 + .../LightAnalysisModeTestGenerated.java | 5 + 68 files changed, 611 insertions(+), 268 deletions(-) create mode 100644 compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt create mode 100644 compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.ir.txt create mode 100644 compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.kt.txt create mode 100644 compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.ir.txt create mode 100644 compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.kt.txt create mode 100644 compiler/testData/ir/irText/expressions/sam/samConversions.fir.ir.txt create mode 100644 compiler/testData/ir/irText/expressions/sam/samConversions.fir.kt.txt diff --git a/analysis/low-level-api-fir/testData/getOrBuildFir/wholeDeclaration/lambdaAsSAMInterfaceWithAnnotation.txt b/analysis/low-level-api-fir/testData/getOrBuildFir/wholeDeclaration/lambdaAsSAMInterfaceWithAnnotation.txt index e87ca0b90fc..3fefb311ba1 100644 --- a/analysis/low-level-api-fir/testData/getOrBuildFir/wholeDeclaration/lambdaAsSAMInterfaceWithAnnotation.txt +++ b/analysis/low-level-api-fir/testData/getOrBuildFir/wholeDeclaration/lambdaAsSAMInterfaceWithAnnotation.txt @@ -4,10 +4,10 @@ FIR source kind: KtRealSourceElementKind FIR element rendered: public final [ResolvedTo(BODY_RESOLVE)] fun resolveMe(): R|kotlin/Unit| { - R|foo/testMe|( = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=@R|foo/Anno|((String(testMe param type ), constant#)) foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|@R|foo/Anno|(position = (String(foo param type ), R|foo/constant|)) foo/Arg|): R|@R|foo/Anno|(position = (String(foo return type ), R|foo/constant|)) foo/Arg| { + R|foo/testMe|( = SAM([ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=@R|foo/Anno|((String(testMe param type ), constant#)) foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|@R|foo/Anno|(position = (String(foo param type ), R|foo/constant|)) foo/Arg|): R|@R|foo/Anno|(position = (String(foo return type ), R|foo/constant|)) foo/Arg| { ^ R|/b| } - ) + )) } FIR FILE: @@ -38,8 +38,8 @@ FILE: [ResolvedTo(IMPORTS)] lambdaAsSAMInterfaceWithAnnotation.kt public final [ResolvedTo(CONTRACTS)] fun testMe([ResolvedTo(CONTRACTS)] f: R|@R|foo/Anno|((String(testMe param type ), constant#)) foo/Foo|): R|kotlin/Unit| { } public final [ResolvedTo(BODY_RESOLVE)] fun resolveMe(): R|kotlin/Unit| { - R|foo/testMe|( = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=@R|foo/Anno|((String(testMe param type ), constant#)) foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|@R|foo/Anno|(position = (String(foo param type ), R|foo/constant|)) foo/Arg|): R|@R|foo/Anno|(position = (String(foo return type ), R|foo/constant|)) foo/Arg| { + R|foo/testMe|( = SAM([ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=@R|foo/Anno|((String(testMe param type ), constant#)) foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|@R|foo/Anno|(position = (String(foo param type ), R|foo/constant|)) foo/Arg|): R|@R|foo/Anno|(position = (String(foo return type ), R|foo/constant|)) foo/Arg| { ^ R|/b| } - ) - } + )) + } \ No newline at end of file diff --git a/analysis/low-level-api-fir/testData/lazyResolve/lambdaAsSAMInterface.txt b/analysis/low-level-api-fir/testData/lazyResolve/lambdaAsSAMInterface.txt index 5ad38136e73..c053f8bd879 100644 --- a/analysis/low-level-api-fir/testData/lazyResolve/lambdaAsSAMInterface.txt +++ b/analysis/low-level-api-fir/testData/lazyResolve/lambdaAsSAMInterface.txt @@ -193,10 +193,10 @@ FILE: [ResolvedTo(IMPORTS)] lambdaAsSAMInterface.kt public final [ResolvedTo(CONTRACTS)] fun testMe([ResolvedTo(CONTRACTS)] f: R|foo/Foo|): R|kotlin/Unit| { } public final [ResolvedTo(BODY_RESOLVE)] fun resolveMe(): R|kotlin/Unit| { - R|foo/testMe|( = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|foo/Arg|): R|foo/Arg| { + R|foo/testMe|( = SAM([ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|foo/Arg|): R|foo/Arg| { ^ R|/b| } - ) + )) } FILE RAW TO BODY: @@ -214,8 +214,8 @@ FILE: [ResolvedTo(BODY_RESOLVE)] lambdaAsSAMInterface.kt public final [ResolvedTo(BODY_RESOLVE)] fun testMe([ResolvedTo(BODY_RESOLVE)] f: R|foo/Foo|): R|kotlin/Unit| { } public final [ResolvedTo(BODY_RESOLVE)] fun resolveMe(): R|kotlin/Unit| { - R|foo/testMe|( = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|foo/Arg|): R|foo/Arg| { + R|foo/testMe|( = SAM([ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|foo/Arg|): R|foo/Arg| { ^ R|/b| } - ) + )) } diff --git a/analysis/low-level-api-fir/testData/lazyResolve/lambdaAsSAMInterfaceScript.txt b/analysis/low-level-api-fir/testData/lazyResolve/lambdaAsSAMInterfaceScript.txt index 45eb49c377a..a5ead798a3f 100644 --- a/analysis/low-level-api-fir/testData/lazyResolve/lambdaAsSAMInterfaceScript.txt +++ b/analysis/low-level-api-fir/testData/lazyResolve/lambdaAsSAMInterfaceScript.txt @@ -288,10 +288,10 @@ FILE: [ResolvedTo(IMPORTS)] lambdaAsSAMInterfaceScript.kts } public final [ResolvedTo(BODY_RESOLVE)] fun resolveMe(): R|kotlin/Unit| { - R|foo/testMe|( = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|foo/Arg|): R|foo/Arg| { + R|foo/testMe|( = SAM([ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|foo/Arg|): R|foo/Arg| { ^ R|/b| } - ) + )) } @@ -317,8 +317,9 @@ FILE: [ResolvedTo(BODY_RESOLVE)] lambdaAsSAMInterfaceScript.kts } public final [ResolvedTo(BODY_RESOLVE)] fun resolveMe(): R|kotlin/Unit| { - R|foo/testMe|( = [ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|foo/Arg|): R|foo/Arg| { + R|foo/testMe|( = SAM([ResolvedTo(BODY_RESOLVE)] [MatchingParameterFunctionTypeKey=foo/Foo] testMe@fun ([ResolvedTo(BODY_RESOLVE)] b: R|foo/Arg|): R|foo/Arg| { ^ R|/b| } - ) + )) } + diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java index ef7be463702..7cbf593faca 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirBlackBoxCodegenBasedTestGenerated.java @@ -50352,6 +50352,12 @@ public class LLFirBlackBoxCodegenBasedTestGenerated extends AbstractLLFirBlackBo runTest("compiler/testData/codegen/box/sam/kt59858.kt"); } + @Test + @TestMetadata("noConversionFromSamToSam.kt") + public void testNoConversionFromSamToSam() throws Exception { + runTest("compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { diff --git a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java index f85125be842..d3d52568019 100644 --- a/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java +++ b/analysis/low-level-api-fir/tests/org/jetbrains/kotlin/analysis/low/level/api/fir/diagnostic/compiler/based/LLFirReversedBlackBoxCodegenBasedTestGenerated.java @@ -50352,6 +50352,12 @@ public class LLFirReversedBlackBoxCodegenBasedTestGenerated extends AbstractLLFi runTest("compiler/testData/codegen/box/sam/kt59858.kt"); } + @Test + @TestMetadata("noConversionFromSamToSam.kt") + public void testNoConversionFromSamToSam() throws Exception { + runTest("compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { diff --git a/compiler/fir/analysis-tests/testData/resolve/inference/javaCollector.fir.txt b/compiler/fir/analysis-tests/testData/resolve/inference/javaCollector.fir.txt index 112b6957f95..0aa37f50010 100644 --- a/compiler/fir/analysis-tests/testData/resolve/inference/javaCollector.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/inference/javaCollector.fir.txt @@ -1,7 +1,7 @@ FILE: javaCollector.kt public final fun foo(): R|kotlin/Unit| { - R|kotlin/collections/listOf|(String()).R|SubstitutionOverride|>|().R|SubstitutionOverride|>|, kotlin/collections/Map?>|, R|ft|>(Q|java/util/stream/Collectors|.R|java/util/stream/Collectors.groupingBy*s||, R|kotlin/Int!|>(groupingBy@fun (it: R|@EnhancedNullability kotlin/String!|): R|@EnhancedNullability kotlin/String!| { + R|kotlin/collections/listOf|(String()).R|SubstitutionOverride|>|().R|SubstitutionOverride|>|, kotlin/collections/Map?>|, R|ft|>(Q|java/util/stream/Collectors|.R|java/util/stream/Collectors.groupingBy*s||, R|kotlin/Int!|>(SAM(groupingBy@fun (it: R|@EnhancedNullability kotlin/String!|): R|@EnhancedNullability kotlin/String!| { ^ R|/it| } - , Q|java/util/stream/Collectors|.R|java/util/stream/Collectors.collectingAndThen*s||, R|kotlin/Long!|, R|kotlin/Int!|>(Q|java/util/stream/Collectors|.R|java/util/stream/Collectors.counting*s|(), Q|kotlin/Long|::R|kotlin/Long.toInt|))) + ), Q|java/util/stream/Collectors|.R|java/util/stream/Collectors.collectingAndThen*s||, R|kotlin/Long!|, R|kotlin/Int!|>(Q|java/util/stream/Collectors|.R|java/util/stream/Collectors.counting*s|(), SAM(Q|kotlin/Long|::R|kotlin/Long.toInt|)))) } diff --git a/compiler/fir/analysis-tests/testData/resolve/rawTypeSam.fir.txt b/compiler/fir/analysis-tests/testData/resolve/rawTypeSam.fir.txt index c2ee46ed09a..5225ee4de2b 100644 --- a/compiler/fir/analysis-tests/testData/resolve/rawTypeSam.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/rawTypeSam.fir.txt @@ -1,7 +1,7 @@ FILE: main.kt public final fun foo(): R|kotlin/Unit| { - Q|RawType|.R|/RawType.bar*s|( = bar@fun (it: R|kotlin/CharSequence!|): R|kotlin/Boolean| { + Q|RawType|.R|/RawType.bar*s|( = SAM(bar@fun (it: R|kotlin/CharSequence!|): R|kotlin/Boolean| { ^ CMP(>, R|/it|.R|kotlin/CharSequence.length|.R|kotlin/Int.compareTo|(Int(0))) } - ) + )) } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/genericSam.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/genericSam.fir.txt index f0032bd6294..81a4cb32ed0 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/genericSam.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/genericSam.fir.txt @@ -1,23 +1,23 @@ FILE: main.kt public final fun main(): R|kotlin/Unit| { - Q|JavaUsage|.R|/JavaUsage.foo1*s|( = foo1@fun (x: R|kotlin/Int!|): R|kotlin/String!| { + Q|JavaUsage|.R|/JavaUsage.foo1*s|( = SAM(foo1@fun (x: R|kotlin/Int!|): R|kotlin/String!| { ^ R|/x|.R|kotlin/Int.toInt|().R|kotlin/Int.toString|() } - ) - Q|JavaUsage|.R|/JavaUsage.foo2*s|( = foo2@fun (x: R|kotlin/Number!|): R|kotlin/CharSequence!| { + )) + Q|JavaUsage|.R|/JavaUsage.foo2*s|( = SAM(foo2@fun (x: R|kotlin/Number!|): R|kotlin/CharSequence!| { ^ R|/x|.R|kotlin/Number.toInt|().R|kotlin/Int.toString|() } - ) + )) Q|JavaUsage|.R|/JavaUsage.foo2*s#|( = foo2@fun (x: R|kotlin/Int|): R|kotlin/CharSequence!| { ^ R|/x|.R|kotlin/Int.toString|() } ) - Q|JavaUsage|.R|/JavaUsage.foo3*s|(foo3@fun (x: R|kotlin/Int!|): R|kotlin/String!| { + Q|JavaUsage|.R|/JavaUsage.foo3*s|(SAM(foo3@fun (x: R|kotlin/Int!|): R|kotlin/String!| { ^ R|/x|.R|kotlin/Int.plus|(Int(1)).R|kotlin/Int.toString|() } - , Int(1)) - Q|JavaUsage|.R|/JavaUsage.foo3*s|(foo3@fun (x: R|kotlin/Number|): R|kotlin/String!| { + ), Int(1)) + Q|JavaUsage|.R|/JavaUsage.foo3*s|(SAM(foo3@fun (x: R|kotlin/Number|): R|kotlin/String!| { ^ R|/x|.R|kotlin/Number.toInt|().R|kotlin/Int.toString|() } - , Int(2)) + ), Int(2)) } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/kotlinSam.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/kotlinSam.fir.txt index 23728e4b8d3..a7894e6c53f 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/kotlinSam.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/kotlinSam.fir.txt @@ -33,11 +33,11 @@ FILE: kotlinSam.kt ^ CMP(>, R|/t|.R|kotlin/Int.compareTo|(Int(1))) } - R|/foo1|( = foo1@fun (x: R|kotlin/Int|): R|kotlin/Boolean| { + R|/foo1|( = SAM(foo1@fun (x: R|kotlin/Int|): R|kotlin/Boolean| { ^ CMP(>, R|/x|.R|kotlin/Int.compareTo|(Int(1))) } - ) - R|/foo1|(R|/f|) + )) + R|/foo1|(SAM(R|/f|)) R|/foo2#|( = foo2@fun (x: R|kotlin/Nothing|): R|kotlin/Boolean| { ^ CMP(>, R|/x|.#(Int(1))) } @@ -48,9 +48,9 @@ FILE: kotlinSam.kt } ) R|/foo3#|(R|/f|) - R|/foo4|( = foo4@fun (x: R|kotlin/Int|): R|kotlin/Boolean| { + R|/foo4|( = SAM(foo4@fun (x: R|kotlin/Int|): R|kotlin/Boolean| { ^ CMP(>, R|/x|.R|kotlin/Int.compareTo|(Int(1))) } - ) - R|/foo4|(R|/f|) + )) + R|/foo4|(SAM(R|/f|)) } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/nothingVararg.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/nothingVararg.fir.txt index 4bccc6965b2..d8409753154 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/nothingVararg.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/nothingVararg.fir.txt @@ -1,7 +1,7 @@ FILE: main.kt public final fun test(x: R|A<*>|): R|kotlin/Unit| { - R|/x|.R|SubstitutionOverride|(vararg(call@fun (y: R|kotlin/Any?|): R|kotlin/Unit| { + R|/x|.R|SubstitutionOverride|(vararg(SAM(call@fun (y: R|kotlin/Any?|): R|kotlin/Unit| { Q|kotlin/Unit| } - )) + ))) } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/runnable.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/runnable.fir.txt index 7feea90c35e..5bc07e404cf 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/runnable.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/runnable.fir.txt @@ -1,11 +1,11 @@ FILE: main.kt public final fun main(): R|kotlin/Unit| { - Q|JavaClass|.R|/JavaClass.foo*s|( = foo@fun (): R|kotlin/Unit| { + Q|JavaClass|.R|/JavaClass.foo*s|( = SAM(foo@fun (): R|kotlin/Unit| { String() } - ) - R|/JavaClass.JavaClass|().R|/JavaClass.bar|( = bar@fun (): R|kotlin/Unit| { + )) + R|/JavaClass.JavaClass|().R|/JavaClass.bar|( = SAM(bar@fun (): R|kotlin/Unit| { String() } - ) + )) } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/samConversionInConstructorCall.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/samConversionInConstructorCall.fir.txt index 54a4042beba..2e872a7d7d3 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/samConversionInConstructorCall.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/samConversionInConstructorCall.fir.txt @@ -1,7 +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|/Foo.Foo|( = SAM(Foo@fun (it: R|kotlin/Boolean|): R|kotlin/Boolean| { ^ R|/it| } - ) + )) } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/samSupertype.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/samSupertype.fir.txt index 21354a8cedc..c898f8e5eb7 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/samSupertype.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/samSupertype.fir.txt @@ -2,17 +2,17 @@ FILE: main.kt public final fun foo(m: R|MyRunnable|): R|kotlin/Unit| { } public final fun main(): R|kotlin/Unit| { - Q|JavaUsage|.R|/JavaUsage.foo*s|( = foo@fun (x: R|kotlin/Int|): R|kotlin/Boolean| { + Q|JavaUsage|.R|/JavaUsage.foo*s|( = SAM(foo@fun (x: R|kotlin/Int|): R|kotlin/Boolean| { ^ CMP(>, R|/x|.R|kotlin/Int.compareTo|(Int(1))) } - ) - Q|JavaUsage|.R|/JavaUsage.foo*s|(foo@fun (it: R|kotlin/Int|): R|kotlin/Boolean| { + )) + Q|JavaUsage|.R|/JavaUsage.foo*s|(SAM(foo@fun (it: R|kotlin/Int|): R|kotlin/Boolean| { ^ CMP(>, R|/it|.R|kotlin/Int.compareTo|(Int(1))) } - ) + )) lval x: R|(kotlin/Int) -> kotlin/Boolean| = fun (x: R|kotlin/Int|): R|kotlin/Boolean| { ^ CMP(>, R|/x|.R|kotlin/Int.compareTo|(Int(1))) } - Q|JavaUsage|.R|/JavaUsage.foo*s|(R|/x|) + Q|JavaUsage|.R|/JavaUsage.foo*s|(SAM(R|/x|)) } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/samSupertypeWithOverride.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/samSupertypeWithOverride.fir.txt index d887df7b435..38b1a33fdce 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/samSupertypeWithOverride.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/samSupertypeWithOverride.fir.txt @@ -2,17 +2,17 @@ FILE: main.kt public final fun foo(m: R|MyRunnable|): R|kotlin/Unit| { } public final fun main(): R|kotlin/Unit| { - Q|JavaUsage|.R|/JavaUsage.foo*s|( = foo@fun (x: R|kotlin/Int|): R|kotlin/Boolean!| { + Q|JavaUsage|.R|/JavaUsage.foo*s|( = SAM(foo@fun (x: R|kotlin/Int|): R|kotlin/Boolean!| { ^ CMP(>, R|/x|.R|kotlin/Int.compareTo|(Int(1))) } - ) - Q|JavaUsage|.R|/JavaUsage.foo*s|(foo@fun (it: R|kotlin/Int|): R|kotlin/Boolean!| { + )) + Q|JavaUsage|.R|/JavaUsage.foo*s|(SAM(foo@fun (it: R|kotlin/Int|): R|kotlin/Boolean!| { ^ CMP(>, R|/it|.R|kotlin/Int.compareTo|(Int(1))) } - ) + )) lval x: R|(kotlin/Int) -> kotlin/Boolean| = fun (x: R|kotlin/Int|): R|kotlin/Boolean| { ^ CMP(>, R|/x|.R|kotlin/Int.compareTo|(Int(1))) } - Q|JavaUsage|.R|/JavaUsage.foo*s|(R|/x|) + Q|JavaUsage|.R|/JavaUsage.foo*s|(SAM(R|/x|)) } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/samVsLambda.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/samVsLambda.fir.txt index b4dd4c2f092..0c318248084 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/samVsLambda.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/samVsLambda.fir.txt @@ -14,8 +14,8 @@ FILE: package2.kt } FILE: main.kt public final fun main(): R|kotlin/Unit| { - R|p1/bar|(String(), String(), = bar@fun (): R|kotlin/Unit| { + R|p1/bar|(String(), String(), = SAM(bar@fun (): R|kotlin/Unit| { ^@bar Unit } - ) + )) } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/samWithEquals.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/samWithEquals.fir.txt index 60d4dcc05f6..1cd86443396 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/samWithEquals.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/samWithEquals.fir.txt @@ -5,7 +5,7 @@ FILE: main.kt } public final fun main(): R|kotlin/Unit| { - Q|OverridingUtil|.R|/OverridingUtil.createWithEqualityAxioms*s|( = l1@fun (c1: R|TypeConstructor!|, c2: R|TypeConstructor!|): R|kotlin/Boolean| { + Q|OverridingUtil|.R|/OverridingUtil.createWithEqualityAxioms*s|( = SAM(l1@fun (c1: R|TypeConstructor!|, c2: R|TypeConstructor!|): R|kotlin/Boolean| { when () { ==(R|/c1|.R|/TypeConstructor.x|, R|/c2|.R|/TypeConstructor.x|) -> { ^@l1 Boolean(true) @@ -14,5 +14,5 @@ FILE: main.kt ^ Boolean(false) } - ) + )) } diff --git a/compiler/fir/analysis-tests/testData/resolve/samConversions/simple.fir.txt b/compiler/fir/analysis-tests/testData/resolve/samConversions/simple.fir.txt index 21354a8cedc..c898f8e5eb7 100644 --- a/compiler/fir/analysis-tests/testData/resolve/samConversions/simple.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolve/samConversions/simple.fir.txt @@ -2,17 +2,17 @@ FILE: main.kt public final fun foo(m: R|MyRunnable|): R|kotlin/Unit| { } public final fun main(): R|kotlin/Unit| { - Q|JavaUsage|.R|/JavaUsage.foo*s|( = foo@fun (x: R|kotlin/Int|): R|kotlin/Boolean| { + Q|JavaUsage|.R|/JavaUsage.foo*s|( = SAM(foo@fun (x: R|kotlin/Int|): R|kotlin/Boolean| { ^ CMP(>, R|/x|.R|kotlin/Int.compareTo|(Int(1))) } - ) - Q|JavaUsage|.R|/JavaUsage.foo*s|(foo@fun (it: R|kotlin/Int|): R|kotlin/Boolean| { + )) + Q|JavaUsage|.R|/JavaUsage.foo*s|(SAM(foo@fun (it: R|kotlin/Int|): R|kotlin/Boolean| { ^ CMP(>, R|/it|.R|kotlin/Int.compareTo|(Int(1))) } - ) + )) lval x: R|(kotlin/Int) -> kotlin/Boolean| = fun (x: R|kotlin/Int|): R|kotlin/Boolean| { ^ CMP(>, R|/x|.R|kotlin/Int.compareTo|(Int(1))) } - Q|JavaUsage|.R|/JavaUsage.foo*s|(R|/x|) + Q|JavaUsage|.R|/JavaUsage.foo*s|(SAM(R|/x|)) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/referenceToJavaStdlib.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/referenceToJavaStdlib.fir.txt index ca18796a012..a90d0838043 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/referenceToJavaStdlib.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/referenceToJavaStdlib.fir.txt @@ -1,6 +1,6 @@ FILE: referenceToJavaStdlib.kt public final fun detectDirsWithTestsMapFileOnly(file: R|java/io/File|): R|kotlin/collections/List| { - Q|java/nio/file/Files|.R|java/nio/file/Files.walk*s|(R|/file|.R|java/io/File.toPath|()).R|SubstitutionOverride, java/util/stream/Stream?>|>|(Q|java/nio/file/Files|::R|java/nio/file/Files.isRegularFile*s|) + Q|java/nio/file/Files|.R|java/nio/file/Files.walk*s|(R|/file|.R|java/io/File.toPath|()).R|SubstitutionOverride, java/util/stream/Stream?>|>|(SAM(Q|java/nio/file/Files|::R|java/nio/file/Files.isRegularFile*s|)) } public abstract interface A : R|kotlin/Any| { } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/sam.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/sam.fir.txt index db40d58dfd5..1933e0e3b1a 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/sam.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/callableReferences/sam.fir.txt @@ -16,5 +16,5 @@ FILE: sam.kt } public final fun main(): R|kotlin/Unit| { lval a: R|A| = R|/A.A|() - R|/foo|(R|/a|::R|/A.bar|) + R|/foo|(SAM(R|/a|::R|/A.bar|)) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashTableWithForEach.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashTableWithForEach.fir.txt index 72dbfa14fcb..25bc67bcd48 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashTableWithForEach.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/hashTableWithForEach.fir.txt @@ -14,10 +14,10 @@ FILE: hashTableWithForEach.kt when () { R|/DEBUG| -> { ^ Q|java/util/Collections|.R|java/util/Collections.unmodifiableSet*s|, kotlin/collections/MutableMap.MutableEntry?>|>(R|kotlin/collections/mutableSetOf||>().R|kotlin/apply|>|>( = apply@fun R|kotlin/collections/MutableSet>|.(): R|kotlin/Unit| { - this@R|/SomeHashTable|.R|/SomeHashTable.forEach|( = forEach@fun (key: R|@EnhancedNullability K|, value: R|@EnhancedNullability V|): R|kotlin/Unit| { + this@R|/SomeHashTable|.R|/SomeHashTable.forEach|( = SAM(forEach@fun (key: R|@EnhancedNullability K|, value: R|@EnhancedNullability V|): R|kotlin/Unit| { this@R|special/anonymous|.R|SubstitutionOverride|(R|/SomeHashTable.Entry.Entry|(R|/key|, R|/value|)) } - ) + )) } )) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/MapCompute.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/MapCompute.fir.txt index e4d88ab8b20..a13cedd9489 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/MapCompute.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/MapCompute.fir.txt @@ -1,9 +1,9 @@ FILE: MapCompute.kt public final fun R|kotlin/collections/MutableMap>|.initAndAdd(key: R|kotlin/String|, value: R|D|): R|kotlin/Unit| { - this@R|/initAndAdd|.R|SubstitutionOverride?|>|(R|/key|, = compute@fun (: R|@EnhancedNullability kotlin/String|, maybeValues: R|@EnhancedNullability kotlin/collections/MutableSet?|): R|@EnhancedNullability kotlin/collections/MutableSet?| { + this@R|/initAndAdd|.R|SubstitutionOverride?|>|(R|/key|, = SAM(compute@fun (: R|@EnhancedNullability kotlin/String|, maybeValues: R|@EnhancedNullability kotlin/collections/MutableSet?|): R|@EnhancedNullability kotlin/collections/MutableSet?| { lval setOfValues: R|kotlin/collections/MutableSet| = R|/maybeValues| ?: R|kotlin/collections/mutableSetOf|() R|/setOfValues|.R|SubstitutionOverride|(R|/value|) ^ R|/setOfValues| } - ) + )) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/MyMap.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/MyMap.fir.txt index d11ffb5d3ea..1f90b9dcf7b 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/MyMap.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/MyMap.fir.txt @@ -6,12 +6,12 @@ FILE: test.kt ) lval otherResult: R|kotlin/String!| = R|/map|.R|SubstitutionOverride|(String(key), String(value)) lval anotherResult: R|kotlin/String?| = R|/map|.R|SubstitutionOverride|(String(key), String(value)) - R|/map|.R|SubstitutionOverride|( = forEach@fun (key: R|@EnhancedNullability kotlin/String!|, value: R|@EnhancedNullability kotlin/String!|): R|kotlin/Unit| { + R|/map|.R|SubstitutionOverride|( = SAM(forEach@fun (key: R|@EnhancedNullability kotlin/String!|, value: R|@EnhancedNullability kotlin/String!|): R|kotlin/Unit| { R|kotlin/io/println|((R|/key|, String(: ), R|/value|)) R|/key|.R|kotlin/String.length| R|/value|.R|kotlin/String.length| } - ) + )) R|/map|.R|kotlin/collections/forEach|( = forEach@fun (: R|kotlin/collections/Map.Entry|): R|kotlin/Unit| { lval key: R|kotlin/String!| = R|/|.R|kotlin/collections/component1|() lval value: R|kotlin/String!| = R|/|.R|kotlin/collections/component2|() @@ -31,12 +31,12 @@ FILE: test.kt ) lval otherResult: R|kotlin/String| = R|/map|.R|SubstitutionOverride|(String(key), String(value)) lval anotherResult: R|kotlin/String?| = R|/map|.R|SubstitutionOverride|(String(key), String(value)) - R|/map|.R|SubstitutionOverride|( = forEach@fun (key: R|@EnhancedNullability kotlin/String|, value: R|@EnhancedNullability kotlin/String|): R|kotlin/Unit| { + R|/map|.R|SubstitutionOverride|( = SAM(forEach@fun (key: R|@EnhancedNullability kotlin/String|, value: R|@EnhancedNullability kotlin/String|): R|kotlin/Unit| { R|kotlin/io/println|((R|/key|, String(: ), R|/value|)) R|/key|.R|kotlin/String.length| R|/value|.R|kotlin/String.length| } - ) + )) R|/map|.R|kotlin/collections/forEach|( = forEach@fun (: R|kotlin/collections/Map.Entry|): R|kotlin/Unit| { lval key: R|kotlin/String| = R|/|.R|kotlin/collections/component1|() lval value: R|kotlin/String| = R|/|.R|kotlin/collections/component2|() diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/SyntheticWithForEach.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/SyntheticWithForEach.fir.txt index f56dd54d3cf..5c965332d47 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/SyntheticWithForEach.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/SyntheticWithForEach.fir.txt @@ -1,10 +1,10 @@ FILE: test.kt public final fun R|Call|.testForEach(): R|kotlin/Unit| { - this@R|/testForEach|.R|/Call.arguments|.R|SubstitutionOverride|( = forEach@fun (key: R|@EnhancedNullability kotlin/String!|, value: R|@EnhancedNullability kotlin/String!|): R|kotlin/Unit| { + this@R|/testForEach|.R|/Call.arguments|.R|SubstitutionOverride|( = SAM(forEach@fun (key: R|@EnhancedNullability kotlin/String!|, value: R|@EnhancedNullability kotlin/String!|): R|kotlin/Unit| { R|/key|.R|kotlin/String.length| R|/value|.R|kotlin/String.length| } - ) + )) this@R|/testForEach|.R|/Call.arguments|.R|kotlin/collections/forEach|( = forEach@fun (it: R|kotlin/collections/Map.Entry|): R|kotlin/Unit| { R|/it|.R|SubstitutionOverride|.R|kotlin/String.length| R|/it|.R|SubstitutionOverride|.R|kotlin/String.length| diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/mapMerge.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/mapMerge.fir.txt index 286ffd4757f..ff88e527239 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/mapMerge.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/j+k/mapMerge.fir.txt @@ -1,7 +1,7 @@ FILE: mapMerge.kt public final fun foo(x: R|kotlin/collections/MutableMap>|): R|kotlin/Unit| { - R|/x|.R|SubstitutionOverride?|>|(String(), R|kotlin/collections/listOf|(String()), = merge@fun (a: R|@EnhancedNullability kotlin/collections/List|, b: R|@EnhancedNullability kotlin/collections/List|): R|@EnhancedNullability kotlin/collections/List?| { + R|/x|.R|SubstitutionOverride?|>|(String(), R|kotlin/collections/listOf|(String()), = SAM(merge@fun (a: R|@EnhancedNullability kotlin/collections/List|, b: R|@EnhancedNullability kotlin/collections/List|): R|@EnhancedNullability kotlin/collections/List?| { ^ R|/a|.R|kotlin/collections/plus|(R|/b|) } - ) + )) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/isAncestor.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/isAncestor.fir.txt index cc234218e35..58a870067f0 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/isAncestor.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/problems/isAncestor.fir.txt @@ -2,10 +2,10 @@ FILE: test.kt public final fun foo(): R|kotlin/Unit| { lval externalsMap: R|kotlin/collections/MutableMap| = R|kotlin/collections/mutableMapOf|() local final fun test(file: R|java/io/File|): R|kotlin/Unit| { - lval base: R|java/io/File!| = Q|your/ContainerUtil|.R|your/ContainerUtil.find*s|(R|/externalsMap|.R|SubstitutionOverride|>|, = find@fun (it: R|java/io/File!|): R|kotlin/Boolean| { + lval base: R|java/io/File!| = Q|your/ContainerUtil|.R|your/ContainerUtil.find*s|(R|/externalsMap|.R|SubstitutionOverride|>|, = SAM(find@fun (it: R|java/io/File!|): R|kotlin/Boolean| { ^ Q|my/FileUtil|.R|my/FileUtil.isAncestor*s|(R|/it|, R|/file|, Boolean(false)) } - ) + )) } } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/removeIf.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/removeIf.fir.txt index 43fec3c16a8..adc1f7436fc 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/removeIf.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/removeIf.fir.txt @@ -1,7 +1,7 @@ FILE: removeIf.kt public final fun test(collection: R|kotlin/collections/MutableCollection|): R|kotlin/Unit| { - R|/collection|.R|SubstitutionOverride|( = removeIf@fun (it: R|@EnhancedNullability kotlin/Boolean|): R|kotlin/Boolean| { + R|/collection|.R|SubstitutionOverride|( = SAM(removeIf@fun (it: R|@EnhancedNullability kotlin/Boolean|): R|kotlin/Boolean| { ^ R|/it| } - ) + )) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/samForComparator.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/samForComparator.fir.txt index 7c478d2a506..d07aebcdd25 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/samForComparator.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/samForComparator.fir.txt @@ -2,8 +2,8 @@ FILE: samForComparator.kt public final fun foo(x: R|kotlin/Comparator|): R|kotlin/Unit| { } public final fun main(): R|kotlin/Unit| { - R|/foo|( = foo@fun (x: R|kotlin/CharSequence!|, y: R|kotlin/CharSequence!|): R|kotlin/Int| { + R|/foo|( = SAM(foo@fun (x: R|kotlin/CharSequence!|, y: R|kotlin/CharSequence!|): R|kotlin/Int| { ^ R|/x|.R|kotlin/CharSequence.length|.R|kotlin/Int.minus|(R|/y|.R|kotlin/CharSequence.length|) } - ) + )) } diff --git a/compiler/fir/analysis-tests/testData/resolveWithStdlib/typeAliasWithForEach.fir.txt b/compiler/fir/analysis-tests/testData/resolveWithStdlib/typeAliasWithForEach.fir.txt index de414a6595d..e00e26606fe 100644 --- a/compiler/fir/analysis-tests/testData/resolveWithStdlib/typeAliasWithForEach.fir.txt +++ b/compiler/fir/analysis-tests/testData/resolveWithStdlib/typeAliasWithForEach.fir.txt @@ -10,10 +10,10 @@ FILE: typeAliasWithForEach.kt public final typealias Arguments = R|kotlin/collections/Map| public final fun R|Arguments|.deepCopy(): R|Arguments| { lval result: R|java/util/HashMap| = R|java/util/HashMap.HashMap|() - this@R|/deepCopy|.R|SubstitutionOverride|( = forEach@fun (key: R|@EnhancedNullability kotlin/String|, value: R|@EnhancedNullability ArgsInfo|): R|kotlin/Unit| { + this@R|/deepCopy|.R|SubstitutionOverride|( = SAM(forEach@fun (key: R|@EnhancedNullability kotlin/String|, value: R|@EnhancedNullability ArgsInfo|): R|kotlin/Unit| { R|/result|.R|kotlin/collections/set|(R|/key|, R|/ArgsInfoImpl.ArgsInfoImpl|(R|/value|)) Unit } - ) + )) ^deepCopy R|/result| } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt index 06b7a6879ad..bacb86dd97a 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrVisitor.kt @@ -531,6 +531,10 @@ class Fir2IrVisitor( return convertToIrExpression(wrappedArgumentExpression.expression) } + override fun visitSamConversionExpression(samConversionExpression: FirSamConversionExpression, data: Any?): IrElement { + return convertToIrExpression(samConversionExpression.expression) + } + override fun visitVarargArgumentsExpression(varargArgumentsExpression: FirVarargArgumentsExpression, data: Any?): IrElement { return varargArgumentsExpression.convertWithOffsets { startOffset, endOffset -> IrVarargImpl( diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt index 171de447c6d..1c47bb80ed7 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/AdapterGenerator.kt @@ -17,14 +17,9 @@ import org.jetbrains.kotlin.fir.render import org.jetbrains.kotlin.fir.resolve.FirSamResolver import org.jetbrains.kotlin.fir.resolve.calls.FirFakeArgumentForCallableReference import org.jetbrains.kotlin.fir.resolve.calls.ResolvedCallArgument -import org.jetbrains.kotlin.fir.resolve.calls.getExpectedType -import org.jetbrains.kotlin.fir.resolve.calls.isFunctional import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor -import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor import org.jetbrains.kotlin.fir.resolve.toFirRegularClassSymbol import org.jetbrains.kotlin.fir.resolve.toSymbol -import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculatorForFullBodyResolve -import org.jetbrains.kotlin.fir.scopes.processAllCallables import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol @@ -44,7 +39,6 @@ import org.jetbrains.kotlin.ir.types.impl.makeTypeProjection import org.jetbrains.kotlin.ir.util.* import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames -import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.types.model.TypeVariance @@ -64,23 +58,6 @@ internal class AdapterGenerator( private val samResolver = FirSamResolver(session, scopeSession) - private val starProjectionApproximator = object : AbstractConeSubstitutor(session.typeContext) { - override fun substituteType(type: ConeKotlinType): ConeKotlinType? { - if (type !is ConeClassLikeType || type.typeArguments.none { it == ConeStarProjection }) return null - val fir = type.lookupTag.toSymbol(session)?.fir as? FirTypeParameterRefsOwner ?: return null - val typeParameters = fir.typeParameters.map { it.symbol.fir } - if (typeParameters.size != type.typeArguments.size) return null - val newTypeArguments = typeParameters.zip(type.typeArguments).map { (parameter, argument) -> - if (argument == ConeStarProjection) { - parameter.bounds.first().coneType - } else { - argument - } - } - return type.withArguments(newTypeArguments.toTypedArray()) - } - } - private fun ConeKotlinType.toIrType(typeOrigin: ConversionTypeOrigin = ConversionTypeOrigin.DEFAULT): IrType = with(typeConverter) { toIrType(typeOrigin) } @@ -422,8 +399,6 @@ internal class AdapterGenerator( internal fun IrExpression.applySamConversionIfNeeded( argument: FirExpression, parameter: FirValueParameter?, - substitutor: ConeSubstitutor, - shouldUnwrapVarargType: Boolean = false ): IrExpression { if (parameter == null) { return this @@ -431,28 +406,19 @@ internal class AdapterGenerator( if (this is IrVararg) { // element-wise SAM conversion if and only if we can build 1-to-1 mapping for elements. return applyConversionOnVararg(argument) { firVarargArgument -> - applySamConversionIfNeeded(firVarargArgument, parameter, substitutor, shouldUnwrapVarargType = true) + applySamConversionIfNeeded(firVarargArgument, parameter) } } - if (!needSamConversion(argument, parameter)) { - return this - } - val parameterType = parameter.returnTypeRef.coneType - val substitutedParameterType = - starProjectionApproximator.substituteOrSelf(substitutor.substituteOrSelf(parameterType)).let { - if (shouldUnwrapVarargType) - it.arrayElementType() ?: it - else - it - } - val samFirType = substitutedParameterType.removeExternalProjections() ?: substitutedParameterType - if (!samFirType.isSamType) return this + val unwrappedArgument = argument.unwrapArgument() + if (unwrappedArgument !is FirSamConversionExpression) return this + + val samFirType = unwrappedArgument.resolvedType.let { it.removeExternalProjections() ?: it } val samType = samFirType.toIrType(ConversionTypeOrigin.DEFAULT) // Make sure the converted IrType owner indeed has a single abstract method, since FunctionReferenceLowering relies on it. return IrTypeOperatorCallImpl( this.startOffset, this.endOffset, samType, IrTypeOperator.SAM_CONVERSION, samType, - castArgumentToFunctionalInterfaceForSamType(this, argument.resolvedType, samFirType) + castArgumentToFunctionalInterfaceForSamType(this, unwrappedArgument.expression.resolvedType, samFirType) ) } @@ -494,7 +460,7 @@ internal class AdapterGenerator( val parameter = parameters.getOrNull(i) ?: return null when { - argument.getVariance() == TypeVariance.IN -> { + !argument.isStarProjection() && argument.getVariance() == TypeVariance.IN -> { // Just erasing `in` from the type projection would lead to an incorrect type for the SAM adapter, // and error at runtime on JVM if invokedynamic + LambdaMetafactory is used, see KT-51868. // So we do it "carefully". If we have a class `A` and a method that takes e.g. `A`, we check @@ -551,39 +517,6 @@ internal class AdapterGenerator( return this } - private fun needSamConversion(argument: FirExpression, parameter: FirValueParameter): Boolean { - // If the type of the argument is already an explicitly subtype of the type of the parameter, we don't need SAM conversion. - if ( - AbstractTypeChecker.isSubtypeOf( - session.typeContext.newTypeCheckerState( - errorTypesEqualToAnything = false, stubTypesEqualToAnything = true - ), - argument.resolvedType, - parameter.returnTypeRef.coneType, - isFromNullabilityConstraint = true - ) - ) { - return false - } - // If the expected type is a built-in functional type, we don't need SAM conversion. - val expectedType = argument.getExpectedType(parameter) - if (expectedType.isTypeParameterBased() || expectedType.isSomeFunctionType(session)) { - return false - } - // On the other hand, the actual type should be either a functional type or a subtype of a class that has a contributed `invoke`. - val expectedFunctionType = getFunctionTypeForPossibleSamType(parameter.returnTypeRef.coneType) - return argument.isFunctional(session, scopeSession, expectedFunctionType, ReturnTypeCalculatorForFullBodyResolve.Default) - } - - private fun ConeKotlinType.isTypeParameterBased(): Boolean { - return when (this) { - is ConeTypeParameterType -> true - is ConeDefinitelyNotNullType -> original.isTypeParameterBased() - is ConeFlexibleType -> lowerBound.isTypeParameterBased() - else -> false - } - } - internal fun getFunctionTypeForPossibleSamType(parameterType: ConeKotlinType): ConeKotlinType? { return samResolver.getFunctionTypeForPossibleSamType(parameterType) } @@ -640,7 +573,7 @@ internal class AdapterGenerator( expectedFunctionalType: ConeClassLikeType, argument: FirExpression ): IrSimpleFunctionSymbol? { - val argumentType = argument.resolvedType + val argumentType = ((argument as? FirSamConversionExpression)?.expression ?: argument).resolvedType val argumentTypeWithInvoke = argumentType.findSubtypeOfBasicFunctionType(session, expectedFunctionalType) ?: return null return if (argumentTypeWithInvoke.isSomeFunctionType(session)) { @@ -837,19 +770,4 @@ internal class AdapterGenerator( irAdapterFunction.parent = conversionScope.parent()!! } } - - context(Fir2IrComponents) - private val ConeKotlinType.isSamType: Boolean - get() { - val classSymbol = this.lowerBoundIfFlexible().toRegularClassSymbol(session) ?: return false - if (!classSymbol.isInterface) return false - val scope = classSymbol.unsubstitutedScope() - var abstractNumber = 0 - scope.processAllCallables { - if (it.isAbstract) { - abstractNumber++ - } - } - return abstractNumber == 1 - } } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt index 08d048e2281..fb670f7ccb7 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/generators/CallAndReferenceGenerator.kt @@ -1062,8 +1062,6 @@ class CallAndReferenceGenerator( irArgument = irArgument.insertSpecialCast(argument, argumentType, unsubstitutedParameterType) } } - // TODO: Applying SAM conversion should be extracted to a separate function, which will call - // convertArgument with original functional type as expected type, see KT-62847, KT-63345 with(adapterGenerator) { if (parameter?.returnTypeRef is FirResolvedTypeRef) { // Java type case (from annotations) @@ -1071,7 +1069,7 @@ class CallAndReferenceGenerator( val unwrappedParameterType = if (parameter.isVararg) parameterType.arrayElementType()!! else parameterType val samFunctionType = getFunctionTypeForPossibleSamType(unwrappedParameterType) irArgument = irArgument.applySuspendConversionIfNeeded(argument, samFunctionType ?: unwrappedParameterType) - irArgument = irArgument.applySamConversionIfNeeded(argument, parameter, substitutor) + irArgument = irArgument.applySamConversionIfNeeded(argument, parameter) } } return irArgument diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java index 8ba55454b20..1e2251a6021 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenTestGenerated.java @@ -49813,6 +49813,12 @@ public class FirLightTreeBlackBoxCodegenTestGenerated extends AbstractFirLightTr runTest("compiler/testData/codegen/box/sam/kt59858.kt"); } + @Test + @TestMetadata("noConversionFromSamToSam.kt") + public void testNoConversionFromSamToSam() throws Exception { + runTest("compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java index da06256275e..03d3b00cb91 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated.java @@ -49813,6 +49813,12 @@ public class FirLightTreeBlackBoxCodegenWithIrFakeOverrideGeneratorTestGenerated runTest("compiler/testData/codegen/box/sam/kt59858.kt"); } + @Test + @TestMetadata("noConversionFromSamToSam.kt") + public void testNoConversionFromSamToSam() throws Exception { + runTest("compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java index ee5520d2b3d..d179b9ba68b 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/codegen/FirPsiBlackBoxCodegenTestGenerated.java @@ -49813,6 +49813,12 @@ public class FirPsiBlackBoxCodegenTestGenerated extends AbstractFirPsiBlackBoxCo runTest("compiler/testData/codegen/box/sam/kt59858.kt"); } + @Test + @TestMetadata("noConversionFromSamToSam.kt") + public void testNoConversionFromSamToSam() throws Exception { + runTest("compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { 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 63d5cf46f5e..1707543c875 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,12 +7,10 @@ package org.jetbrains.kotlin.fir.resolve.calls import org.jetbrains.kotlin.builtins.functions.isBasicFunctionOrKFunction import org.jetbrains.kotlin.config.LanguageFeature -import org.jetbrains.kotlin.fir.FirSession +import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.FirCallableDeclaration import org.jetbrains.kotlin.fir.declarations.FirValueParameter import org.jetbrains.kotlin.fir.expressions.* -import org.jetbrains.kotlin.fir.languageVersionSettings -import org.jetbrains.kotlin.fir.lookupTracker import org.jetbrains.kotlin.fir.references.FirResolvedNamedReference import org.jetbrains.kotlin.fir.references.toResolvedCallableSymbol import org.jetbrains.kotlin.fir.resolve.* @@ -23,7 +21,6 @@ import org.jetbrains.kotlin.fir.resolve.inference.preprocessCallableReference import org.jetbrains.kotlin.fir.resolve.inference.preprocessLambdaArgument import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator import org.jetbrains.kotlin.fir.resolve.transformers.ensureResolvedTypeDeclaration -import org.jetbrains.kotlin.fir.returnExpressions import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag import org.jetbrains.kotlin.fir.symbols.ConeTypeParameterLookupTag import org.jetbrains.kotlin.fir.types.* @@ -39,7 +36,6 @@ import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.model.CaptureStatus import org.jetbrains.kotlin.types.model.TypeSystemCommonSuperTypesContext import org.jetbrains.kotlin.types.model.typeConstructor -import org.jetbrains.kotlin.utils.addToStdlib.runIf val SAM_LOOKUP_NAME = Name.special("") @@ -496,16 +492,29 @@ private fun Candidate.getExpectedTypeWithSAMConversion( scopeSession: ScopeSession, argument: FirExpression, candidateExpectedType: ConeKotlinType, - context: ResolutionContext + context: ResolutionContext, ): ConeKotlinType? { if (candidateExpectedType.isSomeFunctionType(session)) return null val expectedFunctionType = context.bodyResolveComponents.samResolver.getFunctionTypeForPossibleSamType(candidateExpectedType) ?: return null - return runIf(argument.isFunctional(session, scopeSession, expectedFunctionType, context.returnTypeCalculator)) { - usesSAM = true - expectedFunctionType + + if (!argument.shouldUseSamConversion( + session, + scopeSession, + candidateExpectedType = candidateExpectedType, + expectedFunctionType = expectedFunctionType, + context.returnTypeCalculator + ) + ) { + return null } + + val samConversions = functionTypesOfSamConversions + ?: hashMapOf().also { functionTypesOfSamConversions = it } + + samConversions[argument.unwrapArgument()] = expectedFunctionType + return expectedFunctionType } private fun getExpectedTypeWithImplicitIntegerCoercion( @@ -531,10 +540,11 @@ private fun getExpectedTypeWithImplicitIntegerCoercion( return argumentType?.withNullability(candidateExpectedType.nullability, session.typeContext) } -fun FirExpression.isFunctional( +fun FirExpression.shouldUseSamConversion( session: FirSession, scopeSession: ScopeSession, - expectedFunctionType: ConeKotlinType?, + candidateExpectedType: ConeKotlinType, + expectedFunctionType: ConeKotlinType, returnTypeCalculator: ReturnTypeCalculator, ): Boolean { when (unwrapArgument()) { @@ -542,10 +552,15 @@ fun FirExpression.isFunctional( else -> { // Either a functional type or a subtype of a class that has a contributed `invoke`. val coneType = resolvedType + // Argument might have an intersection type between FunctionN and the SAM type from a smart cast, in which case we don't want to use + // SAM conversion. + if (coneType.isSubtypeOf(candidateExpectedType, session)) { + return false + } if (coneType.isSomeFunctionType(session)) { return true } - val classLikeExpectedFunctionType = expectedFunctionType?.lowerBoundIfFlexible() as? ConeClassLikeType + val classLikeExpectedFunctionType = expectedFunctionType.lowerBoundIfFlexible() as? ConeClassLikeType if (classLikeExpectedFunctionType == null || coneType is ConeIntegerLiteralType) { return false } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt index 4cf6bbb4113..30304a49996 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/calls/Candidate.kt @@ -84,7 +84,7 @@ class Candidate( lateinit var freshVariables: List var resultingTypeForCallableReference: ConeKotlinType? = null var outerConstraintBuilderEffect: (ConstraintSystemOperation.() -> Unit)? = null - var usesSAM: Boolean = false + val usesSAM: Boolean get() = functionTypesOfSamConversions != null internal var callableReferenceAdaptation: CallableReferenceAdaptation? = null set(value) { @@ -99,6 +99,7 @@ class Candidate( var argumentMapping: LinkedHashMap? = null var numDefaults: Int = 0 + var functionTypesOfSamConversions: HashMap? = null lateinit var typeArgumentMapping: TypeArgumentMapping val postponedAtoms = mutableListOf() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 8d11c60f0e6..cf856a5064a 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -5,6 +5,8 @@ package org.jetbrains.kotlin.fir.resolve.transformers +import org.jetbrains.kotlin.KtFakeSourceElementKind +import org.jetbrains.kotlin.fakeElement import org.jetbrains.kotlin.fir.* import org.jetbrains.kotlin.fir.declarations.* import org.jetbrains.kotlin.fir.declarations.utils.isInline @@ -12,6 +14,7 @@ import org.jetbrains.kotlin.fir.diagnostics.ConeDiagnostic import org.jetbrains.kotlin.fir.diagnostics.ConeSimpleDiagnostic import org.jetbrains.kotlin.fir.diagnostics.DiagnosticKind import org.jetbrains.kotlin.fir.expressions.* +import org.jetbrains.kotlin.fir.expressions.builder.buildSamConversionExpression import org.jetbrains.kotlin.fir.expressions.impl.FirPropertyAccessExpressionImpl import org.jetbrains.kotlin.fir.references.FirNamedReference import org.jetbrains.kotlin.fir.references.builder.buildResolvedCallableReference @@ -316,7 +319,9 @@ class FirCallCompletionResultsWriterTransformer( } } val expectedArgumentsTypeMapping = runIf(!calleeReference.isError) { subCandidate.createArgumentsMapping() } - result.argumentList.transformArguments(this, expectedArgumentsTypeMapping) + + result.transformWithExpectedTypes(expectedArgumentsTypeMapping) + result.replaceConeTypeOrNull(resultType) session.lookupTracker?.recordTypeResolveAsLookup(resultType, functionCall.source, context.file.source) @@ -330,6 +335,45 @@ class FirCallCompletionResultsWriterTransformer( return result } + private fun FirCall.transformWithExpectedTypes(expectedArgumentsTypeMapping: ExpectedArgumentType.ArgumentsMap?) { + class SamConversionInsertionTransformer : FirTransformer() { + override fun transformElement(element: E, data: Nothing?): E { + // We want to handle only the most top-level "real" expressions + // We only recursively transform named, spread, lambda argument and vararg expressions. + if (element is FirWrappedArgumentExpression || element is FirVarargArgumentsExpression) { + @Suppress("UNCHECKED_CAST") + return element.transformChildren(this, null) as E + } + + // Once we encounter the first "real" expression, we delegate to the outer transformer. + val transformed = element.transformSingle(this@FirCallCompletionResultsWriterTransformer, expectedArgumentsTypeMapping) + + // Finally, the result can be wrapped in a SAM conversion if necessary. + if (transformed is FirExpression) { + val key = (element as? FirAnonymousFunctionExpression)?.anonymousFunction ?: element + if (expectedArgumentsTypeMapping?.samFunctionTypes?.get(key) != null) { + val expectedArgumentType = expectedArgumentsTypeMapping.getExpectedType(key) + @Suppress("UNCHECKED_CAST") + expectedArgumentType?.let { return transformed.wrapInSamExpression(it) as E } + } + } + + return transformed + } + } + + argumentList.transformArguments(SamConversionInsertionTransformer(), null) + } + + private fun FirExpression.wrapInSamExpression(expectedArgumentType: ConeKotlinType): FirExpression { + return buildSamConversionExpression { + expression = this@wrapInSamExpression + coneTypeOrNull = expectedArgumentType.withNullability(resolvedType.nullability, session.typeContext) + .let { typeApproximator.approximateToSuperType(it, TypeApproximatorConfiguration.TypeArgumentApproximation) ?: it } + source = this@wrapInSamExpression.source?.fakeElement(KtFakeSourceElementKind.SamConversion) + } + } + private val FirBasedSymbol<*>.isArrayConstructorWithLambda: Boolean get() { val constructor = (this as? FirConstructorSymbol)?.fir ?: return false @@ -501,18 +545,23 @@ class FirCallCompletionResultsWriterTransformer( } } - private fun FirTypeRef.substitute(candidate: Candidate): ConeKotlinType = - coneType.let { candidate.substitutor.substituteOrSelf(it) } - .let { finallySubstituteOrSelf(it) } + private fun FirTypeRef.substitute(candidate: Candidate): ConeKotlinType { + return coneType.substitute(candidate) + } - private fun Candidate.createArgumentsMapping(): ExpectedArgumentType? { + private fun ConeKotlinType.substitute(candidate: Candidate): ConeKotlinType { + return finallySubstituteOrSelf(candidate.substitutor.substituteOrSelf(this)) + } + + private fun Candidate.createArgumentsMapping(): ExpectedArgumentType.ArgumentsMap? { val lambdasReturnType = postponedAtoms.filterIsInstance().associate { Pair(it.atom, finallySubstituteOrSelf(substitutor.substituteOrSelf(it.returnType))) } val isIntegerOperator = symbol.isWrappedIntegerOperator() - val arguments = argumentMapping?.map { (argument, valueParameter) -> + var samConversions: MutableMap? = null + val arguments = argumentMapping?.flatMap { (argument, valueParameter) -> val expectedType = when { isIntegerOperator -> ConeIntegerConstantOperatorTypeImpl( isUnsigned = symbol.isWrappedIntegerOperatorForUnsignedType() && callInfo.name in binaryOperatorsWithSignedArgument, @@ -522,16 +571,19 @@ class FirCallCompletionResultsWriterTransformer( else -> valueParameter.returnTypeRef.substitute(this) } - val unwrappedArgument: FirElement = when (val unwrappedArgument = argument.unwrapArgument()) { - is FirAnonymousFunctionExpression -> unwrappedArgument.anonymousFunction - else -> unwrappedArgument + argument.unwrapAndFlattenArgument(flattenArrays = false).map { + val element: FirElement = (it as? FirAnonymousFunctionExpression)?.anonymousFunction ?: it + val samFunctionType = functionTypesOfSamConversions?.get(it) + if (samFunctionType != null) { + if (samConversions == null) samConversions = mutableMapOf() + samConversions!![element] = samFunctionType.substitute(this) + } + element to expectedType } - unwrappedArgument to expectedType }?.toMap() - if (lambdasReturnType.isEmpty() && arguments.isNullOrEmpty()) return null - return ExpectedArgumentType.ArgumentsMap(arguments ?: emptyMap(), lambdasReturnType) + return ExpectedArgumentType.ArgumentsMap(arguments ?: emptyMap(), lambdasReturnType, samConversions ?: emptyMap()) } override fun transformDelegatedConstructorCall( @@ -554,7 +606,7 @@ class FirCallCompletionResultsWriterTransformer( } val argumentsMapping = runIf(!calleeReference.isError) { subCandidate.createArgumentsMapping() } - delegatedConstructorCall.argumentList.transformArguments(this, argumentsMapping) + delegatedConstructorCall.transformWithExpectedTypes(argumentsMapping) return delegatedConstructorCall.apply { replaceCalleeReference(calleeReference.toResolvedReference()) @@ -637,7 +689,11 @@ class FirCallCompletionResultsWriterTransformer( // a built-in functional type, no-brainer expectedArgumentType.isSomeFunctionType(session) -> expectedArgumentType // fun interface (a.k.a. SAM), then unwrap it and build a functional type from that interface function - else -> samResolver.getFunctionTypeForPossibleSamType(expectedArgumentType)?.lowerBoundIfFlexible() + else -> { + val samFunctionType = (data as? ExpectedArgumentType.ArgumentsMap)?.samFunctionTypes?.get(anonymousFunction) + ?: samResolver.getFunctionTypeForPossibleSamType(expectedArgumentType) + samFunctionType?.lowerBoundIfFlexible() + } } } @@ -896,6 +952,7 @@ sealed class ExpectedArgumentType { class ArgumentsMap( val map: Map, val lambdasReturnTypes: Map, + val samFunctionTypes: Map, ) : ExpectedArgumentType() class ExpectedType(val type: ConeKotlinType) : ExpectedArgumentType() diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt index 3d7114e9bd1..263ef937765 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirExpressionsResolveTransformer.kt @@ -1547,18 +1547,26 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT typeRef = initializer.resolvedType.toFirResolvedTypeRef(initializer.source?.fakeElement(KtFakeSourceElementKind.DesugaredCompoundAssignment)), ) - val indexVariables = lhsGetCall.arguments.flatMap { - if (it is FirVarargArgumentsExpression) - it.arguments - else - listOf(it) - }.mapIndexed { i, index -> + val flattenedGetCallArguments = buildList { + for (argument in lhsGetCall.arguments) { + if (argument is FirVarargArgumentsExpression) { + addAll(argument.arguments) + } else { + add(argument) + } + } + } + val indexVariables = flattenedGetCallArguments.mapIndexed { i, index -> + // If the get call arguments are SAM converted, unwrap the SAM conversion. + // Otherwise, we might fail resolution if the get and set operator parameter types are different + // (different SAM types or one is a SAM type and the other isn't). + val unwrappedSamIndex = (index as? FirSamConversionExpression)?.expression ?: index generateTemporaryVariable( session.moduleData, - source = index.source?.fakeElement(KtFakeSourceElementKind.DesugaredCompoundAssignment), + source = unwrappedSamIndex.source?.fakeElement(KtFakeSourceElementKind.DesugaredCompoundAssignment), name = SpecialNames.subscribeOperatorIndex(i), - initializer = index, - typeRef = index.resolvedType.toFirResolvedTypeRef(), + initializer = unwrappedSamIndex, + typeRef = unwrappedSamIndex.resolvedType.toFirResolvedTypeRef(), ) } @@ -1568,6 +1576,17 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT val arrayAccess = arrayVariable.toQualifiedAccess() val indicesQualifiedAccess = indexVariables.map { it.toQualifiedAccess() } + // If the get call arguments were SAM conversions, they were unwrapped for the variable initializers. + // We need to reapply the SAM conversions here because the get call won't be completed again (where the SAM conversions could be + // applied automatically). + // SAM conversions will be applied automatically for the set call during completion. + val indicesQualifiedAccessForGet = indicesQualifiedAccess.mapIndexed { index, qualifiedAccess -> + val samConversion = flattenedGetCallArguments[index] as? FirSamConversionExpression ?: return@mapIndexed qualifiedAccess + buildSamConversionExpressionCopy(samConversion) { + expression = qualifiedAccess + } + } + val getCall = buildFunctionCall { source = augmentedArraySetCall.arrayAccessSource?.fakeElement(KtFakeSourceElementKind.DesugaredCompoundAssignment) explicitReceiver = arrayAccess @@ -1585,14 +1604,14 @@ open class FirExpressionsResolveTransformer(transformer: FirAbstractBodyResolveT arguments += if (argument is FirVarargArgumentsExpression) { buildVarargArgumentsExpression { val varargSize = argument.arguments.size - arguments += indicesQualifiedAccess.subList(i, i + varargSize) + arguments += indicesQualifiedAccessForGet.subList(i, i + varargSize) i += varargSize source = argument.source coneTypeOrNull = argument.resolvedType varargElementType = argument.varargElementType } } else { - indicesQualifiedAccess[i++] + indicesQualifiedAccessForGet[i++] } } } diff --git a/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt b/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt index 3c727cd23bc..adf7df10e9f 100644 --- a/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt +++ b/compiler/frontend.common/src/org/jetbrains/kotlin/KtSourceElement.kt @@ -288,6 +288,9 @@ sealed class KtFakeSourceElementKind(final override val shouldSkipErrorTypeRepor // For provided parameters inside a script object ScriptParameter : KtFakeSourceElementKind() + + // When a lambda is converted to a SAM type, the expression is wrapped in an extra node + object SamConversion : KtFakeSourceElementKind() } sealed class AbstractKtSourceElement { diff --git a/compiler/testData/codegen/box/sam/kt54600.fir.ir.txt b/compiler/testData/codegen/box/sam/kt54600.fir.ir.txt index 7c7e525986b..175f7609d3c 100644 --- a/compiler/testData/codegen/box/sam/kt54600.fir.ir.txt +++ b/compiler/testData/codegen/box/sam/kt54600.fir.ir.txt @@ -9,8 +9,8 @@ FILE fqName: fileName:/box.kt BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CONSTRUCTOR_CALL 'public constructor (filter: @[FlexibleNullability] .Condition?) declared in .J' type=.J origin=null - filter: TYPE_OP type=@[FlexibleNullability] .Condition? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] .Condition? - TYPE_OP type=@[FlexibleNullability] kotlin.Function1<@[FlexibleNullability] kotlin.Any?, kotlin.Boolean>? origin=IMPLICIT_CAST typeOperand=@[FlexibleNullability] kotlin.Function1<@[FlexibleNullability] kotlin.Any?, kotlin.Boolean>? + filter: TYPE_OP type=.Condition? origin=SAM_CONVERSION typeOperand=.Condition? + TYPE_OP type=kotlin.Function1<@[FlexibleNullability] kotlin.Any?, kotlin.Boolean>? origin=IMPLICIT_CAST typeOperand=kotlin.Function1<@[FlexibleNullability] kotlin.Any?, kotlin.Boolean>? GET_VAR 'filter: kotlin.Function1? declared in .foo' type=kotlin.Function1? origin=null RETURN type=kotlin.Nothing from='public final fun foo (filter: kotlin.Function1?): kotlin.String declared in ' CONST String type=kotlin.String value="OK" diff --git a/compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt b/compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt new file mode 100644 index 00000000000..08b8b6ccb7e --- /dev/null +++ b/compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt @@ -0,0 +1,21 @@ +// TARGET_BACKEND: JVM +// FILE: Sam.java +public interface Sam { + T foo(); +} + +// FILE: Connection.java +public interface Connection { + T accept(Sam sam); +} + +// FILE: box.kt +fun test(sam: Sam<*>, c: Connection): Any { + return c.accept(sam) +} + +fun box(): String { + return test({ "OK" }, object: Connection { + override fun accept(sam: Sam) = sam.foo() + }) as String +} \ No newline at end of file diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.ir.txt index dd90a2d5460..9e0e86afbca 100644 --- a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.ir.txt @@ -6,7 +6,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt : kotlin.String CALL 'public open fun someFunction (hello: @[FlexibleNullability] example.Hello<@[FlexibleNullability] A of example.SomeJavaClass?>?): kotlin.Unit declared in example.SomeJavaClass' type=kotlin.Unit origin=null $this: GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null - hello: TYPE_OP type=@[FlexibleNullability] example.Hello? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] example.Hello? + hello: TYPE_OP type=example.Hello origin=SAM_CONVERSION typeOperand=example.Hello FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:@[FlexibleNullability] kotlin.String? @@ -16,7 +16,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public open fun plus (hello: @[FlexibleNullability] example.Hello<@[FlexibleNullability] A of example.SomeJavaClass?>?): @[FlexibleNullability] example.SomeJavaClass<@[FlexibleNullability] A of example.SomeJavaClass?>? declared in example.SomeJavaClass' type=@[FlexibleNullability] example.SomeJavaClass? origin=PLUS $this: GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null - hello: TYPE_OP type=@[FlexibleNullability] example.Hello? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] example.Hello? + hello: TYPE_OP type=example.Hello origin=SAM_CONVERSION typeOperand=example.Hello FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:@[FlexibleNullability] kotlin.String? @@ -25,7 +25,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit CALL 'public open fun get (hello: @[FlexibleNullability] example.Hello<@[FlexibleNullability] A of example.SomeJavaClass?>?): kotlin.Unit declared in example.SomeJavaClass' type=kotlin.Unit origin=null $this: GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null - hello: TYPE_OP type=@[FlexibleNullability] example.Hello? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] example.Hello? + hello: TYPE_OP type=example.Hello origin=SAM_CONVERSION typeOperand=example.Hello FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:@[FlexibleNullability] kotlin.String? @@ -35,7 +35,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt SET_VAR 'var a: example.SomeJavaClass declared in .test' type=kotlin.Unit origin=EQ CALL 'public open fun plus (hello: @[FlexibleNullability] example.Hello<@[FlexibleNullability] A of example.SomeJavaClass?>?): @[FlexibleNullability] example.SomeJavaClass<@[FlexibleNullability] A of example.SomeJavaClass?>? declared in example.SomeJavaClass' type=@[FlexibleNullability] example.SomeJavaClass? origin=null $this: GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null - hello: TYPE_OP type=@[FlexibleNullability] example.Hello? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] example.Hello? + hello: TYPE_OP type=example.Hello origin=SAM_CONVERSION typeOperand=example.Hello FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:@[FlexibleNullability] kotlin.String? @@ -45,7 +45,7 @@ FILE fqName: fileName:/genericSamProjectedOut.kt CALL 'public open fun set (i: kotlin.Int, hello: @[FlexibleNullability] example.Hello<@[FlexibleNullability] A of example.SomeJavaClass?>?): kotlin.Unit declared in example.SomeJavaClass' type=kotlin.Unit origin=null $this: GET_VAR 'var a: example.SomeJavaClass declared in .test' type=example.SomeJavaClass origin=null i: CONST Int type=kotlin.Int value=0 - hello: TYPE_OP type=@[FlexibleNullability] example.Hello? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] example.Hello? + hello: TYPE_OP type=example.Hello origin=SAM_CONVERSION typeOperand=example.Hello FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] kotlin.String?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[FlexibleNullability] kotlin.String?) returnType:kotlin.Unit VALUE_PARAMETER name:it index:0 type:@[FlexibleNullability] kotlin.String? diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt index 4f719196083..0c5b8e9b4f9 100644 --- a/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/genericSamProjectedOut.fir.kt.txt @@ -3,21 +3,21 @@ fun test() { a.someFunction(hello = local fun (it: @FlexibleNullability String?) { return Unit } - /*-> @FlexibleNullability Hello? */) + /*-> Hello */) a.plus(hello = local fun (it: @FlexibleNullability String?) { return Unit } - /*-> @FlexibleNullability Hello? */) /*~> Unit */ + /*-> Hello */) /*~> Unit */ a.get(hello = local fun (it: @FlexibleNullability String?) { return Unit } - /*-> @FlexibleNullability Hello? */) + /*-> Hello */) a = a.plus(hello = local fun (it: @FlexibleNullability String?) { return Unit } - /*-> @FlexibleNullability Hello? */) + /*-> Hello */) a.set(i = 0, hello = local fun (it: @FlexibleNullability String?) { return Unit } - /*-> @FlexibleNullability Hello? */) + /*-> Hello */) } diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.ir.txt index 711f6eafd1f..85bf555e744 100644 --- a/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.ir.txt @@ -12,7 +12,7 @@ FILE fqName: fileName:/genericSamSmartcast.kt CALL 'public open fun call (block: @[FlexibleNullability] .A.I<@[FlexibleNullability] T of .A?>?): @[FlexibleNullability] kotlin.String? declared in .A' type=@[FlexibleNullability] kotlin.String? origin=null $this: TYPE_OP type=.A<*> origin=IMPLICIT_CAST typeOperand=.A<*> GET_VAR 'x: kotlin.Any declared in .f' type=kotlin.Any origin=null - block: TYPE_OP type=@[FlexibleNullability] .A.I? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] .A.I? + block: TYPE_OP type=.A.I origin=SAM_CONVERSION typeOperand=.A.I FUN_EXPR type=kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (y:kotlin.Any?) returnType:@[FlexibleNullability] kotlin.String? VALUE_PARAMETER name:y index:0 type:kotlin.Any? diff --git a/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.kt.txt index 24c1db00ef8..5fbfd58c8f4 100644 --- a/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/genericSamSmartcast.fir.kt.txt @@ -4,9 +4,8 @@ fun f(x: Any): String { return x /*as A<*> */.call(block = local fun (y: Any?): @FlexibleNullability String? { return "OK" } - /*-> @FlexibleNullability I? */) /*!! String */ + /*-> I */) /*!! String */ } } return "Fail" } - diff --git a/compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.ir.txt new file mode 100644 index 00000000000..b35732fd7a0 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.ir.txt @@ -0,0 +1,11 @@ +FILE fqName: fileName:/samByProjectedType.kt + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public open fun bar (j: @[FlexibleNullability] .J<*>?): kotlin.Unit declared in .H' type=kotlin.Unit origin=null + j: TYPE_OP type=.J<@[FlexibleNullability] kotlin.Any?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.Any?> + FUN_EXPR type=kotlin.Function1 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (x:kotlin.Any) returnType:@[FlexibleNullability] kotlin.Any? + VALUE_PARAMETER name:x index:0 type:kotlin.Any + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (x: kotlin.Any): @[FlexibleNullability] kotlin.Any? declared in .test1' + GET_VAR 'x: kotlin.Any declared in .test1.' type=kotlin.Any origin=null diff --git a/compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.kt.txt new file mode 100644 index 00000000000..e7323635211 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samByProjectedType.fir.kt.txt @@ -0,0 +1,6 @@ +fun test1() { + bar(j = local fun (x: Any): @FlexibleNullability Any? { + return x + } + /*-> J<@FlexibleNullability Any?> */) +} diff --git a/compiler/testData/ir/irText/expressions/sam/samByProjectedType.kt b/compiler/testData/ir/irText/expressions/sam/samByProjectedType.kt index d8a7dc574dc..bade3584433 100644 --- a/compiler/testData/ir/irText/expressions/sam/samByProjectedType.kt +++ b/compiler/testData/ir/irText/expressions/sam/samByProjectedType.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // TARGET_BACKEND: JVM // FILE: samByProjectedType.kt diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.ir.txt new file mode 100644 index 00000000000..9aebf5bcfc3 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.ir.txt @@ -0,0 +1,114 @@ +FILE fqName: fileName:/samConversionInGenericConstructorCall.kt + FUN name:test3 visibility:public modality:FINAL <> (f1:kotlin.Function1, f2:kotlin.Function1) returnType:.C.D<@[FlexibleNullability] kotlin.Int?, @[FlexibleNullability] kotlin.String?> + VALUE_PARAMETER name:f1 index:0 type:kotlin.Function1 + 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): .C.D<@[FlexibleNullability] kotlin.Int?, @[FlexibleNullability] kotlin.String?> declared in ' + CONSTRUCTOR_CALL 'public constructor (jxy: @[FlexibleNullability] .J<@[FlexibleNullability] X of .C?, @[FlexibleNullability] Y of .C.D?>?) declared in .C.D' type=.C.D<@[FlexibleNullability] kotlin.Int?, @[FlexibleNullability] kotlin.String?> origin=null + : @[FlexibleNullability] kotlin.Int? + $outer: CONSTRUCTOR_CALL 'public constructor (jxx: @[FlexibleNullability] .J<@[FlexibleNullability] X of .C?, @[FlexibleNullability] X of .C?>?) declared in .C' type=.C<@[FlexibleNullability] kotlin.String?> origin=null + : @[FlexibleNullability] kotlin.String? + jxx: TYPE_OP type=.J<@[FlexibleNullability] kotlin.String?, @[FlexibleNullability] kotlin.String?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.String?, @[FlexibleNullability] kotlin.String?> + GET_VAR 'f1: kotlin.Function1 declared in .test3' type=kotlin.Function1 origin=null + jxy: TYPE_OP type=.J<@[FlexibleNullability] kotlin.String?, @[FlexibleNullability] kotlin.Int?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.String?, @[FlexibleNullability] kotlin.Int?> + 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> + TYPE_PARAMETER name:T1 index:0 variance: superTypes:[kotlin.Any?] reified:false + CONSTRUCTOR visibility:public <> (j11:.J.Outer, T1 of .Outer>) returnType:.Outer.Outer> [primary] + VALUE_PARAMETER name:j11 index:0 type:.J.Outer, T1 of .Outer> + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Outer modality:FINAL visibility:public superTypes:[kotlin.Any]' + PROPERTY name:j11 visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:j11 type:.J.Outer, T1 of .Outer> visibility:private [final] + EXPRESSION_BODY + GET_VAR 'j11: .J.Outer, T1 of .Outer> declared in .Outer.' type=.J.Outer, T1 of .Outer> origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Outer.Outer>) returnType:.J.Outer, T1 of .Outer> + correspondingProperty: PROPERTY name:j11 visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Outer.Outer> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): .J.Outer, T1 of .Outer> declared in .Outer' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:j11 type:.J.Outer, T1 of .Outer> visibility:private [final]' type=.J.Outer, T1 of .Outer> origin=null + receiver: GET_VAR ': .Outer.Outer> declared in .Outer.' type=.Outer.Outer> origin=null + CLASS CLASS name:Inner modality:FINAL visibility:public [inner] superTypes:[kotlin.Any] + $this: VALUE_PARAMETER INSTANCE_RECEIVER name: type:.Outer.Inner.Outer.Inner, T1 of .Outer> + TYPE_PARAMETER name:T2 index:0 variance: superTypes:[kotlin.Any?] reified:false + CONSTRUCTOR visibility:public <> ($this:.Outer.Outer>, j12:.J.Outer, T2 of .Outer.Inner>) returnType:.Outer.Inner.Outer.Inner, T1 of .Outer> [primary] + $outer: VALUE_PARAMETER name: type:.Outer.Outer> + VALUE_PARAMETER name:j12 index:0 type:.J.Outer, T2 of .Outer.Inner> + BLOCK_BODY + DELEGATING_CONSTRUCTOR_CALL 'public constructor () declared in kotlin.Any' + INSTANCE_INITIALIZER_CALL classDescriptor='CLASS CLASS name:Inner modality:FINAL visibility:public [inner] superTypes:[kotlin.Any]' + PROPERTY name:j12 visibility:public modality:FINAL [val] + FIELD PROPERTY_BACKING_FIELD name:j12 type:.J.Outer, T2 of .Outer.Inner> visibility:private [final] + EXPRESSION_BODY + GET_VAR 'j12: .J.Outer, T2 of .Outer.Inner> declared in .Outer.Inner.' type=.J.Outer, T2 of .Outer.Inner> origin=INITIALIZE_PROPERTY_FROM_PARAMETER + FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:public modality:FINAL <> ($this:.Outer.Inner.Outer.Inner, T1 of .Outer>) returnType:.J.Outer, T2 of .Outer.Inner> + correspondingProperty: PROPERTY name:j12 visibility:public modality:FINAL [val] + $this: VALUE_PARAMETER name: type:.Outer.Inner.Outer.Inner, T1 of .Outer> + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun (): .J.Outer, T2 of .Outer.Inner> declared in .Outer.Inner' + GET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:j12 type:.J.Outer, T2 of .Outer.Inner> visibility:private [final]' type=.J.Outer, T2 of .Outer.Inner> origin=null + receiver: GET_VAR ': .Outer.Inner.Outer.Inner, T1 of .Outer> declared in .Outer.Inner.' type=.Outer.Inner.Outer.Inner, T1 of .Outer> origin=null + 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 declared in kotlin.Any + $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 declared in kotlin.Any + $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 declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + 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 declared in kotlin.Any + $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 declared in kotlin.Any + $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 declared in kotlin.Any + $this: VALUE_PARAMETER name: type:kotlin.Any + FUN name:test4 visibility:public modality:FINAL <> (f:kotlin.Function1, g:kotlin.Function1) returnType:.Outer.Inner<@[FlexibleNullability] kotlin.Any?, @[FlexibleNullability] kotlin.String?> + VALUE_PARAMETER name:f index:0 type:kotlin.Function1 + 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): .Outer.Inner<@[FlexibleNullability] kotlin.Any?, @[FlexibleNullability] kotlin.String?> declared in ' + CONSTRUCTOR_CALL 'public constructor (j12: .J.Outer, T2 of .Outer.Inner>) declared in .Outer.Inner' type=.Outer.Inner<@[FlexibleNullability] kotlin.Any?, @[FlexibleNullability] kotlin.String?> origin=null + : @[FlexibleNullability] kotlin.Any? + $outer: CONSTRUCTOR_CALL 'public constructor (j11: .J.Outer, T1 of .Outer>) declared in .Outer' type=.Outer<@[FlexibleNullability] kotlin.String?> origin=null + : @[FlexibleNullability] kotlin.String? + j11: TYPE_OP type=.J<@[FlexibleNullability] kotlin.String?, @[FlexibleNullability] kotlin.String?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.String?, @[FlexibleNullability] kotlin.String?> + GET_VAR 'f: kotlin.Function1 declared in .test4' type=kotlin.Function1 origin=null + j12: TYPE_OP type=.J<@[FlexibleNullability] kotlin.String?, @[FlexibleNullability] kotlin.Any?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.String?, @[FlexibleNullability] kotlin.Any?> + GET_VAR 'g: kotlin.Function1 declared in .test4' type=kotlin.Function1 origin=null + FUN name:testGenericJavaCtor1 visibility:public modality:FINAL <> (f:kotlin.Function1) returnType:.G<@[FlexibleNullability] kotlin.String?> + VALUE_PARAMETER name:f index:0 type:kotlin.Function1 + BLOCK_BODY + RETURN type=kotlin.Nothing from='public final fun testGenericJavaCtor1 (f: kotlin.Function1): .G<@[FlexibleNullability] kotlin.String?> declared in ' + CONSTRUCTOR_CALL 'public constructor (x: @[FlexibleNullability] .J<@[FlexibleNullability] TCtor of .G.?, @[FlexibleNullability] TClass of .G?>?) declared in .G' type=.G<@[FlexibleNullability] kotlin.String?> origin=null + : @[FlexibleNullability] kotlin.String? + : @[FlexibleNullability] kotlin.Int? + x: TYPE_OP type=.J<@[FlexibleNullability] kotlin.Int?, @[FlexibleNullability] kotlin.String?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.Int?, @[FlexibleNullability] kotlin.String?> + GET_VAR 'f: kotlin.Function1 declared in .testGenericJavaCtor1' type=kotlin.Function1 origin=null + 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.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + TYPE_OP type=kotlin.Function1 origin=CAST typeOperand=kotlin.Function1 + GET_VAR 'x: kotlin.Any declared in .testGenericJavaCtor2' type=kotlin.Any origin=null + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CONSTRUCTOR_CALL 'public constructor (x: @[FlexibleNullability] .J<@[FlexibleNullability] TCtor of .G.?, @[FlexibleNullability] TClass of .G?>?) declared in .G' type=.G<@[FlexibleNullability] kotlin.String?> origin=null + : @[FlexibleNullability] kotlin.String? + : @[FlexibleNullability] kotlin.Int? + x: TYPE_OP type=.J<@[FlexibleNullability] kotlin.Int?, @[FlexibleNullability] kotlin.String?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.Int?, @[FlexibleNullability] kotlin.String?> + TYPE_OP type=kotlin.Function1 origin=IMPLICIT_CAST typeOperand=kotlin.Function1 + GET_VAR 'x: kotlin.Any declared in .testGenericJavaCtor2' type=kotlin.Any origin=null diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.kt.txt new file mode 100644 index 00000000000..c1048ded706 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.fir.kt.txt @@ -0,0 +1,42 @@ +fun test3(f1: Function1, f2: Function1): D<@FlexibleNullability Int?, @FlexibleNullability String?> { + return C<@FlexibleNullability String?>(jxx = f1 /*-> J<@FlexibleNullability String?, @FlexibleNullability String?> */).D<@FlexibleNullability Int?>(jxy = f2 /*-> J<@FlexibleNullability String?, @FlexibleNullability Int?> */) +} + +class Outer { + constructor(j11: J) /* primary */ { + super/*Any*/() + /* () */ + + } + + val j11: J + field = j11 + get + + inner class Inner { + constructor(j12: J) /* primary */ { + super/*Any*/() + /* () */ + + } + + val j12: J + field = j12 + get + + } + +} + +fun test4(f: Function1, g: Function1): Inner<@FlexibleNullability Any?, @FlexibleNullability String?> { + return Outer<@FlexibleNullability String?>(j11 = f /*-> J<@FlexibleNullability String?, @FlexibleNullability String?> */).Inner<@FlexibleNullability Any?>(j12 = g /*-> J<@FlexibleNullability String?, @FlexibleNullability Any?> */) +} + +fun testGenericJavaCtor1(f: Function1): G<@FlexibleNullability String?> { + return G<@FlexibleNullability String?, @FlexibleNullability Int?>(x = f /*-> J<@FlexibleNullability Int?, @FlexibleNullability String?> */) +} + +fun testGenericJavaCtor2(x: Any) { + x as Function1 /*~> Unit */ + G<@FlexibleNullability String?, @FlexibleNullability Int?>(x = x /*as Function1 */ /*-> J<@FlexibleNullability Int?, @FlexibleNullability String?> */) /*~> Unit */ +} diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.kt b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.kt index 822cf972c11..2da5a9df572 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.kt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // TARGET_BACKEND: JVM // FILE: samConversionInGenericConstructorCall.kt diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.kt.txt index 19eb35d5b51..4de1ad8e837 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionInGenericConstructorCall.kt.txt @@ -40,3 +40,4 @@ fun testGenericJavaCtor2(x: Any) { x as Function1 /*~> Unit */ G<@FlexibleNullability String?, @FlexibleNullability Int?>(x = x /*as Function1 */ /*-> @FlexibleNullability J<@FlexibleNullability Int?, @FlexibleNullability String?>? */) /*~> Unit */ } + diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.ir.txt index 0433313d775..3506aea4819 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.ir.txt @@ -24,7 +24,7 @@ FILE fqName: fileName:/samConversionToGeneric.kt RETURN type=kotlin.Nothing from='public final fun test3 (): kotlin.Unit declared in ' CALL 'public open fun bar (j: @[FlexibleNullability] .J<@[FlexibleNullability] X of .H.bar?>?): kotlin.Unit declared in .H' type=kotlin.Unit origin=null : @[FlexibleNullability] kotlin.String? - j: TYPE_OP type=@[FlexibleNullability] .J<@[FlexibleNullability] kotlin.String?>? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] .J<@[FlexibleNullability] kotlin.String?>? + j: TYPE_OP type=.J<@[FlexibleNullability] kotlin.String?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.String?> FUN_EXPR type=kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (x:kotlin.String) returnType:@[FlexibleNullability] kotlin.String? VALUE_PARAMETER name:x index:0 type:kotlin.String @@ -49,7 +49,7 @@ FILE fqName: fileName:/samConversionToGeneric.kt GET_VAR 'a: kotlin.Any declared in .test5' type=kotlin.Any origin=null CALL 'public open fun bar (j: @[FlexibleNullability] .J<@[FlexibleNullability] X of .H.bar?>?): kotlin.Unit declared in .H' type=kotlin.Unit origin=null : @[FlexibleNullability] kotlin.String? - j: TYPE_OP type=@[FlexibleNullability] .J<@[FlexibleNullability] kotlin.String?>? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] .J<@[FlexibleNullability] kotlin.String?>? + j: TYPE_OP type=.J<@[FlexibleNullability] kotlin.String?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.String?> TYPE_OP type=kotlin.Function1 origin=IMPLICIT_CAST typeOperand=kotlin.Function1 GET_VAR 'a: kotlin.Any declared in .test5' type=kotlin.Any origin=null FUN name:test6 visibility:public modality:FINAL (a:kotlin.Function1.test6, T of .test6>) returnType:kotlin.Unit @@ -58,7 +58,7 @@ FILE fqName: fileName:/samConversionToGeneric.kt BLOCK_BODY CALL 'public open fun bar (j: @[FlexibleNullability] .J<@[FlexibleNullability] X of .H.bar?>?): kotlin.Unit declared in .H' type=kotlin.Unit origin=null : @[FlexibleNullability] T of .test6? - j: TYPE_OP type=@[FlexibleNullability] .J<@[FlexibleNullability] T of .test6?>? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] .J<@[FlexibleNullability] T of .test6?>? + j: TYPE_OP type=.J<@[FlexibleNullability] T of .test6?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] T of .test6?> GET_VAR 'a: kotlin.Function1.test6, T of .test6> declared in .test6' type=kotlin.Function1.test6, T of .test6> origin=null FUN name:test7 visibility:public modality:FINAL (a:kotlin.Any) returnType:kotlin.Unit TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] reified:false @@ -69,7 +69,7 @@ FILE fqName: fileName:/samConversionToGeneric.kt GET_VAR 'a: kotlin.Any declared in .test7' type=kotlin.Any origin=null CALL 'public open fun bar (j: @[FlexibleNullability] .J<@[FlexibleNullability] X of .H.bar?>?): kotlin.Unit declared in .H' type=kotlin.Unit origin=null : @[FlexibleNullability] T of .test7? - j: TYPE_OP type=@[FlexibleNullability] .J<@[FlexibleNullability] T of .test7?>? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] .J<@[FlexibleNullability] T of .test7?>? + j: TYPE_OP type=.J<@[FlexibleNullability] T of .test7?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] T of .test7?> TYPE_OP type=kotlin.Function1.test7, T of .test7> origin=IMPLICIT_CAST typeOperand=kotlin.Function1.test7, T of .test7> GET_VAR 'a: kotlin.Any declared in .test7' type=kotlin.Any origin=null FUN name:test8 visibility:public modality:FINAL <> (efn:@[ExtensionFunctionType] kotlin.Function1) returnType:.J<@[FlexibleNullability] kotlin.String?> @@ -83,12 +83,12 @@ FILE fqName: fileName:/samConversionToGeneric.kt BLOCK_BODY CALL 'public open fun bar (j: @[FlexibleNullability] .J<@[FlexibleNullability] X of .H.bar?>?): kotlin.Unit declared in .H' type=kotlin.Unit origin=null : @[FlexibleNullability] kotlin.String? - j: TYPE_OP type=@[FlexibleNullability] .J<@[FlexibleNullability] kotlin.String?>? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] .J<@[FlexibleNullability] kotlin.String?>? + j: TYPE_OP type=.J<@[FlexibleNullability] kotlin.String?> origin=SAM_CONVERSION typeOperand=.J<@[FlexibleNullability] kotlin.String?> GET_VAR 'efn: @[ExtensionFunctionType] kotlin.Function1 declared in .test9' type=@[ExtensionFunctionType] kotlin.Function1 origin=null FUN name:test10 visibility:public modality:FINAL <> (fn:kotlin.Function1) returnType:kotlin.Unit VALUE_PARAMETER name:fn index:0 type:kotlin.Function1 BLOCK_BODY CALL 'public open fun bar2x (j2x: @[FlexibleNullability] .J2X<@[FlexibleNullability] Y of .H.bar2x?>?): kotlin.Unit declared in .H' type=kotlin.Unit origin=null : @[FlexibleNullability] kotlin.Int? - j2x: TYPE_OP type=@[FlexibleNullability] .J2X<@[FlexibleNullability] kotlin.Int?>? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] .J2X<@[FlexibleNullability] kotlin.Int?>? + j2x: TYPE_OP type=.J2X<@[FlexibleNullability] kotlin.Int?> origin=SAM_CONVERSION typeOperand=.J2X<@[FlexibleNullability] kotlin.Int?> GET_VAR 'fn: kotlin.Function1 declared in .test10' type=kotlin.Function1 origin=null diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt index 777d3e82313..4b5201bcc10 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionToGeneric.fir.kt.txt @@ -16,7 +16,7 @@ fun test3() { return bar<@FlexibleNullability String?>(j = local fun (x: String): @FlexibleNullability String? { return x } - /*-> @FlexibleNullability J<@FlexibleNullability String?>? */) + /*-> J<@FlexibleNullability String?> */) } fun test4(a: Any) { @@ -26,16 +26,16 @@ fun test4(a: Any) { fun test5(a: Any) { a as Function1 /*~> Unit */ - bar<@FlexibleNullability String?>(j = a /*as Function1 */ /*-> @FlexibleNullability J<@FlexibleNullability String?>? */) + bar<@FlexibleNullability String?>(j = a /*as Function1 */ /*-> J<@FlexibleNullability String?> */) } fun test6(a: Function1) { - bar<@FlexibleNullability T?>(j = a /*-> @FlexibleNullability J<@FlexibleNullability T?>? */) + bar<@FlexibleNullability T?>(j = a /*-> J<@FlexibleNullability T?> */) } fun test7(a: Any) { a as Function1 /*~> Unit */ - bar<@FlexibleNullability T?>(j = a /*as Function1 */ /*-> @FlexibleNullability J<@FlexibleNullability T?>? */) + bar<@FlexibleNullability T?>(j = a /*as Function1 */ /*-> J<@FlexibleNullability T?> */) } fun test8(efn: @ExtensionFunctionType Function1): J<@FlexibleNullability String?> { @@ -43,9 +43,9 @@ fun test8(efn: @ExtensionFunctionType Function1): J<@FlexibleNul } fun test9(efn: @ExtensionFunctionType Function1) { - bar<@FlexibleNullability String?>(j = efn /*-> @FlexibleNullability J<@FlexibleNullability String?>? */) + bar<@FlexibleNullability String?>(j = efn /*-> J<@FlexibleNullability String?> */) } fun test10(fn: Function1) { - bar2x<@FlexibleNullability Int?>(j2x = fn /*-> @FlexibleNullability J2X<@FlexibleNullability Int?>? */) + bar2x<@FlexibleNullability Int?>(j2x = fn /*-> J2X<@FlexibleNullability Int?> */) } diff --git a/compiler/testData/ir/irText/expressions/sam/samConversions.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/samConversions.fir.ir.txt new file mode 100644 index 00000000000..5b013a497ef --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samConversions.fir.ir.txt @@ -0,0 +1,54 @@ +FILE fqName: fileName:/samConversions.kt + FUN name:test0 visibility:public modality:FINAL <> ($receiver:.J, a:java.lang.Runnable) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:.J + VALUE_PARAMETER name:a index:0 type:java.lang.Runnable + BLOCK_BODY + CALL 'public open fun runStatic (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null + r: GET_VAR 'a: java.lang.Runnable declared in .test0' type=java.lang.Runnable origin=null + CALL 'public open fun runIt (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null + $this: GET_VAR ': .J declared in .test0' type=.J origin=null + r: GET_VAR 'a: java.lang.Runnable declared in .test0' type=java.lang.Runnable origin=null + FUN name:test1 visibility:public modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public open fun runStatic (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null + r: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun test1 (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + FUN name:test2 visibility:public modality:FINAL <> ($receiver:.J) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:.J + BLOCK_BODY + CALL 'public open fun runIt (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null + $this: GET_VAR ': .J declared in .test2' type=.J origin=null + r: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable + FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + CALL 'public final fun test1 (): kotlin.Unit declared in ' type=kotlin.Unit origin=null + FUN name:test3 visibility:public modality:FINAL <> ($receiver:.J, a:kotlin.Function0) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:.J + VALUE_PARAMETER name:a index:0 type:kotlin.Function0 + BLOCK_BODY + CALL 'public open fun run2 (r1: @[FlexibleNullability] java.lang.Runnable?, r2: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null + $this: GET_VAR ': .J declared in .test3' type=.J origin=null + r1: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable + GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null + r2: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable + GET_VAR 'a: kotlin.Function0 declared in .test3' type=kotlin.Function0 origin=null + FUN name:test4 visibility:public modality:FINAL <> ($receiver:.J, a:kotlin.Function0, b:kotlin.Function0, flag:kotlin.Boolean) returnType:kotlin.Unit + $receiver: VALUE_PARAMETER name: type:.J + VALUE_PARAMETER name:a index:0 type:kotlin.Function0 + VALUE_PARAMETER name:b index:1 type:kotlin.Function0 + VALUE_PARAMETER name:flag index:2 type:kotlin.Boolean + BLOCK_BODY + CALL 'public open fun runIt (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null + $this: GET_VAR ': .J declared in .test4' type=.J origin=null + r: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable + WHEN type=kotlin.Function0 origin=IF + BRANCH + if: GET_VAR 'flag: kotlin.Boolean declared in .test4' type=kotlin.Boolean origin=null + then: GET_VAR 'a: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null + BRANCH + if: CONST Boolean type=kotlin.Boolean value=true + then: GET_VAR 'b: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null diff --git a/compiler/testData/ir/irText/expressions/sam/samConversions.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversions.fir.kt.txt new file mode 100644 index 00000000000..f3986cf3a61 --- /dev/null +++ b/compiler/testData/ir/irText/expressions/sam/samConversions.fir.kt.txt @@ -0,0 +1,29 @@ +fun J.test0(a: Runnable) { + runStatic(r = a) + .runIt(r = a) +} + +fun test1() { + runStatic(r = local fun () { + test1() + } + /*-> Runnable */) +} + +fun J.test2() { + .runIt(r = local fun () { + test1() + } + /*-> Runnable */) +} + +fun J.test3(a: Function0) { + .run2(r1 = a /*-> Runnable */, r2 = a /*-> Runnable */) +} + +fun J.test4(a: Function0, b: Function0, flag: Boolean) { + .runIt(r = when { + flag -> a + else -> b + } /*-> Runnable */) +} diff --git a/compiler/testData/ir/irText/expressions/sam/samConversions.kt b/compiler/testData/ir/irText/expressions/sam/samConversions.kt index 9c6027ee654..c0cb0bbe694 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversions.kt +++ b/compiler/testData/ir/irText/expressions/sam/samConversions.kt @@ -1,4 +1,3 @@ -// FIR_IDENTICAL // TARGET_BACKEND: JVM // WITH_JDK diff --git a/compiler/testData/ir/irText/expressions/sam/samConversions.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversions.kt.txt index ce287d8109e..6cb66288544 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversions.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversions.kt.txt @@ -27,3 +27,4 @@ fun J.test4(a: Function0, b: Function0, flag: Boolean) { else -> b } /*-> @FlexibleNullability Runnable? */) } + diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.ir.txt index 2efbfd24ec3..a842958304f 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.ir.txt @@ -49,7 +49,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt $this: CONSTRUCTOR_CALL 'public constructor () declared in .J' type=.J origin=null r1: TYPE_OP type=java.lang.Runnable origin=IMPLICIT_CAST typeOperand=java.lang.Runnable GET_VAR 'a: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null - r2: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + r2: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable GET_VAR 'b: kotlin.Function0 declared in .test4' type=kotlin.Function0 origin=null FUN name:test5 visibility:public modality:FINAL <> (a:kotlin.Any) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Any @@ -87,7 +87,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt GET_VAR 'a: kotlin.Any declared in .test6' type=kotlin.Any origin=null CALL 'public open fun run1 (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: CONSTRUCTOR_CALL 'public constructor () declared in .J' type=.J origin=null - r: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + r: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable TYPE_OP type=kotlin.Function0 origin=IMPLICIT_CAST typeOperand=kotlin.Function0 GET_VAR 'a: kotlin.Any declared in .test6' type=kotlin.Any origin=null FUN name:test7 visibility:public modality:FINAL <> (a:kotlin.Function1) returnType:kotlin.Unit @@ -98,7 +98,7 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null CALL 'public open fun run1 (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: CONSTRUCTOR_CALL 'public constructor () declared in .J' type=.J origin=null - r: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + r: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable GET_VAR 'a: kotlin.Function1 declared in .test7' type=kotlin.Function1 origin=null FUN name:test8 visibility:public modality:FINAL <> (a:kotlin.Function0) returnType:kotlin.Unit VALUE_PARAMETER name:a index:0 type:kotlin.Function0 @@ -113,5 +113,5 @@ FILE fqName: fileName:/samConversionsWithSmartCasts.kt BLOCK_BODY CALL 'public open fun run1 (r: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: CONSTRUCTOR_CALL 'public constructor () declared in .J' type=.J origin=null - r: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + r: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun test9 (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt index 3cce03d83ee..01ff674e970 100644 --- a/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/samConversionsWithSmartCasts.fir.kt.txt @@ -25,7 +25,7 @@ fun test3(a: Function0) { fun test4(a: Function0, b: Function0) { when { a is Runnable -> { // BLOCK - J().run2(r1 = a /*as Runnable */, r2 = b /*-> @FlexibleNullability Runnable? */) + J().run2(r1 = a /*as Runnable */, r2 = b /*-> Runnable */) } } } @@ -49,12 +49,12 @@ fun test5x(a: Any) { fun test6(a: Any) { a as Function0 /*~> Unit */ - J().run1(r = a /*as Function0 */ /*-> @FlexibleNullability Runnable? */) + J().run1(r = a /*as Function0 */ /*-> Runnable */) } fun test7(a: Function1) { a as Function0 /*~> Unit */ - J().run1(r = a /*-> @FlexibleNullability Runnable? */) + J().run1(r = a /*-> Runnable */) } fun test8(a: Function0) { @@ -62,6 +62,5 @@ fun test8(a: Function0) { } fun test9() { - J().run1(r = ::test9 /*-> @FlexibleNullability Runnable? */) + J().run1(r = ::test9 /*-> Runnable */) } - diff --git a/compiler/testData/ir/irText/expressions/sam/samOperators.fir.ir.txt b/compiler/testData/ir/irText/expressions/sam/samOperators.fir.ir.txt index 14f07e3d66b..c4cee807bf8 100644 --- a/compiler/testData/ir/irText/expressions/sam/samOperators.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/sam/samOperators.fir.ir.txt @@ -6,39 +6,39 @@ FILE fqName: fileName:/samOperators.kt BLOCK_BODY CALL 'public open fun get (k: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: GET_VAR ': .J declared in .test1' type=.J origin=null - k: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + k: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun f (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= CALL 'public open fun get (k: @[FlexibleNullability] java.lang.Runnable?, m: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: GET_VAR ': .J declared in .test1' type=.J origin=null - k: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + k: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun f (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= - m: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + m: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun f (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= FUN name:test2 visibility:public modality:FINAL <> ($receiver:.J) returnType:kotlin.Unit $receiver: VALUE_PARAMETER name: type:.J BLOCK_BODY CALL 'public open fun set (k: @[FlexibleNullability] java.lang.Runnable?, v: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: GET_VAR ': .J declared in .test2' type=.J origin=null - k: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + k: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun f (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= - v: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + v: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun f (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= CALL 'public open fun set (k: @[FlexibleNullability] java.lang.Runnable?, m: @[FlexibleNullability] java.lang.Runnable?, v: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=null $this: GET_VAR ': .J declared in .test2' type=.J origin=null - k: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + k: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun f (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= - m: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + m: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun f (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= - v: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + v: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun f (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= FUN name:test3 visibility:public modality:FINAL <> ($receiver:.J) returnType:kotlin.Unit $receiver: VALUE_PARAMETER name: type:.J BLOCK_BODY CALL 'public open fun plusAssign (i: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=PLUSEQ $this: GET_VAR ': .J declared in .test3' type=.J origin=null - i: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + i: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun f (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= CALL 'public open fun minusAssign (i: @[FlexibleNullability] java.lang.Runnable?): kotlin.Unit declared in .J' type=kotlin.Unit origin=MINUSEQ $this: GET_VAR ': .J declared in .test3' type=.J origin=null - i: TYPE_OP type=@[FlexibleNullability] java.lang.Runnable? origin=SAM_CONVERSION typeOperand=@[FlexibleNullability] java.lang.Runnable? + i: TYPE_OP type=java.lang.Runnable origin=SAM_CONVERSION typeOperand=java.lang.Runnable FUNCTION_REFERENCE 'public final fun f (): kotlin.Unit declared in ' type=kotlin.reflect.KFunction0 origin=null reflectionTarget= diff --git a/compiler/testData/ir/irText/expressions/sam/samOperators.fir.kt.txt b/compiler/testData/ir/irText/expressions/sam/samOperators.fir.kt.txt index 0ab5c6b9b34..d6fbdb2017c 100644 --- a/compiler/testData/ir/irText/expressions/sam/samOperators.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/sam/samOperators.fir.kt.txt @@ -2,16 +2,16 @@ fun f() { } fun J.test1() { - .get(k = ::f /*-> @FlexibleNullability Runnable? */) - .get(k = ::f /*-> @FlexibleNullability Runnable? */, m = ::f /*-> @FlexibleNullability Runnable? */) + .get(k = ::f /*-> Runnable */) + .get(k = ::f /*-> Runnable */, m = ::f /*-> Runnable */) } fun J.test2() { - .set(k = ::f /*-> @FlexibleNullability Runnable? */, v = ::f /*-> @FlexibleNullability Runnable? */) - .set(k = ::f /*-> @FlexibleNullability Runnable? */, m = ::f /*-> @FlexibleNullability Runnable? */, v = ::f /*-> @FlexibleNullability Runnable? */) + .set(k = ::f /*-> Runnable */, v = ::f /*-> Runnable */) + .set(k = ::f /*-> Runnable */, m = ::f /*-> Runnable */, v = ::f /*-> Runnable */) } fun J.test3() { - .plusAssign(i = ::f /*-> @FlexibleNullability Runnable? */) - .minusAssign(i = ::f /*-> @FlexibleNullability Runnable? */) + .plusAssign(i = ::f /*-> Runnable */) + .minusAssign(i = ::f /*-> Runnable */) } diff --git a/compiler/testData/ir/irText/firProblems/kt19251.fir.ir.txt b/compiler/testData/ir/irText/firProblems/kt19251.fir.ir.txt index d97d4293c12..1cff466105b 100644 --- a/compiler/testData/ir/irText/firProblems/kt19251.fir.ir.txt +++ b/compiler/testData/ir/irText/firProblems/kt19251.fir.ir.txt @@ -17,7 +17,7 @@ FILE fqName: fileName:/test.kt CALL 'public open fun computeIfAbsent (p0: @[EnhancedNullability] K of kotlin.collections.MutableMap, p1: @[EnhancedNullability] java.util.function.Function): @[EnhancedNullability] V of kotlin.collections.MutableMap declared in kotlin.collections.MutableMap' type=@[EnhancedNullability] kotlin.String origin=null $this: GET_VAR 'val map: kotlin.collections.MutableMap<.Fun, kotlin.String> declared in .box' type=kotlin.collections.MutableMap<.Fun, kotlin.String> origin=null p0: GET_VAR 'val fn: .Fun declared in .box' type=.Fun origin=null - p1: TYPE_OP type=@[EnhancedNullability] java.util.function.Function origin=SAM_CONVERSION typeOperand=@[EnhancedNullability] java.util.function.Function + p1: TYPE_OP type=java.util.function.Function origin=SAM_CONVERSION typeOperand=java.util.function.Function TYPE_OP type=kotlin.Function1<@[EnhancedNullability] kotlin.Any?, @[EnhancedNullability] kotlin.String> origin=IMPLICIT_CAST typeOperand=kotlin.Function1<@[EnhancedNullability] kotlin.Any?, @[EnhancedNullability] kotlin.String> FUN_EXPR type=kotlin.Function1<@[EnhancedNullability] .Fun, @[EnhancedNullability] kotlin.String> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (it:@[EnhancedNullability] .Fun) returnType:@[EnhancedNullability] kotlin.String diff --git a/compiler/testData/ir/irText/firProblems/kt19251.fir.kt.txt b/compiler/testData/ir/irText/firProblems/kt19251.fir.kt.txt index cf710bd0530..ce7c942cb0a 100644 --- a/compiler/testData/ir/irText/firProblems/kt19251.fir.kt.txt +++ b/compiler/testData/ir/irText/firProblems/kt19251.fir.kt.txt @@ -7,5 +7,5 @@ fun box(): String { return map.computeIfAbsent(p0 = fn, p1 = local fun (it: @EnhancedNullability Fun): @EnhancedNullability String { return "OK" } - /*as Function1<@EnhancedNullability Any?, @EnhancedNullability String> */ /*-> @EnhancedNullability Function */) /*!! String */ + /*as Function1<@EnhancedNullability Any?, @EnhancedNullability String> */ /*-> Function */) /*!! String */ } 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 681b0230276..aa5de0aff3e 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 @@ -46831,6 +46831,12 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest { runTest("compiler/testData/codegen/box/sam/kt59858.kt"); } + @Test + @TestMetadata("noConversionFromSamToSam.kt") + public void testNoConversionFromSamToSam() throws Exception { + runTest("compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() 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 6ff8a87991d..6fe7f89bd68 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 @@ -49813,6 +49813,12 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes runTest("compiler/testData/codegen/box/sam/kt59858.kt"); } + @Test + @TestMetadata("noConversionFromSamToSam.kt") + public void testNoConversionFromSamToSam() throws Exception { + runTest("compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java index 47b3d302d82..4606d33e246 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/codegen/IrBlackBoxCodegenWithIrInlinerTestGenerated.java @@ -49813,6 +49813,12 @@ public class IrBlackBoxCodegenWithIrInlinerTestGenerated extends AbstractIrBlack runTest("compiler/testData/codegen/box/sam/kt59858.kt"); } + @Test + @TestMetadata("noConversionFromSamToSam.kt") + public void testNoConversionFromSamToSam() throws Exception { + runTest("compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt"); + } + @Test @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() 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 5804390b732..535c1454147 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/codegen/LightAnalysisModeTestGenerated.java @@ -40003,6 +40003,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes runTest("compiler/testData/codegen/box/sam/kt59858.kt"); } + @TestMetadata("noConversionFromSamToSam.kt") + public void testNoConversionFromSamToSam() throws Exception { + runTest("compiler/testData/codegen/box/sam/noConversionFromSamToSam.kt"); + } + @TestMetadata("nonInlinedSamWrapper.kt") public void testNonInlinedSamWrapper() throws Exception { runTest("compiler/testData/codegen/box/sam/nonInlinedSamWrapper.kt");