From e1f6c19c83479cab0137d18561ce7f092997a0b3 Mon Sep 17 00:00:00 2001 From: Mads Ager Date: Thu, 28 Oct 2021 13:49:57 +0200 Subject: [PATCH] [FIR] Fix local variable tests. - Mangle names for extension receivers in lambdas - Correctly mark anonymous variables and variables for arguments for destructuring declaration. There is one failure remaining which is cause by lambda type inference differences that leads to FIR having an explicit return from the lambda whereas old frontend leads to an implicit return. This difference is visible in debug stepping that the local variables tests do because the implicit return has the line number of the closing brace of the lambda. This change adds an IrText test to make the difference clear. --- .../kotlin/fir/backend/ConversionUtils.kt | 22 +++++++++++++++---- .../fir/backend/Fir2IrDeclarationStorage.kt | 7 +++++- .../runners/ir/Fir2IrTextTestGenerated.java | 6 +++++ .../noSymbolForIntRangeIterator.fir.ir.txt | 4 ++-- .../debug/localVariables/suspend/mergeLvt.kt | 2 ++ .../irText/classes/initValInLambda.fir.ir.txt | 2 +- .../ir/irText/expressions/kt37570.fir.ir.txt | 4 ++-- .../ir/irText/expressions/kt37570.fir.kt.txt | 3 ++- .../ir/irText/expressions/kt47082.fir.ir.txt | 4 ++-- .../ir/irText/expressions/kt47082.fir.kt.txt | 3 ++- .../firProblems/AllCandidates.fir.ir.txt | 4 ++-- .../firProblems/AllCandidates.fir.kt.txt | 3 ++- .../typeVariableAfterBuildMap.fir.ir.txt | 12 +++++----- .../typeVariableAfterBuildMap.fir.kt.txt | 11 +++++----- .../lambdas/destructuringInLambda.fir.ir.txt | 2 +- .../irText/lambdas/extensionLambda.fir.ir.txt | 4 ++-- .../irText/lambdas/extensionLambda.fir.kt.txt | 3 ++- .../lambdas/lambdaReturningUnit.fir.ir.txt | 15 +++++++++++++ .../lambdas/lambdaReturningUnit.fir.kt.txt | 10 +++++++++ .../irText/lambdas/lambdaReturningUnit.ir.txt | 14 ++++++++++++ .../ir/irText/lambdas/lambdaReturningUnit.kt | 12 ++++++++++ .../irText/lambdas/lambdaReturningUnit.kt.txt | 11 ++++++++++ .../multipleImplicitReceivers.fir.ir.txt | 12 +++++----- .../multipleImplicitReceivers.fir.kt.txt | 3 ++- .../ir/irText/stubs/builtinMap.fir.ir.txt | 4 ++-- .../ir/irText/stubs/builtinMap.fir.kt.txt | 3 ++- .../castsInsideCoroutineInference.fir.ir.txt | 22 +++++++++---------- .../castsInsideCoroutineInference.fir.kt.txt | 11 +++++----- .../test/runners/ir/IrTextTestGenerated.java | 6 +++++ .../test/backend/handlers/DebugRunner.kt | 22 +++++++++++++++++-- .../kotlin/ir/KlibTextTestCaseGenerated.java | 5 +++++ 31 files changed, 186 insertions(+), 60 deletions(-) create mode 100644 compiler/testData/ir/irText/lambdas/lambdaReturningUnit.fir.ir.txt create mode 100644 compiler/testData/ir/irText/lambdas/lambdaReturningUnit.fir.kt.txt create mode 100644 compiler/testData/ir/irText/lambdas/lambdaReturningUnit.ir.txt create mode 100644 compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt create mode 100644 compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt.txt diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt index b8713caaeaa..5d34c893c4a 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/ConversionUtils.kt @@ -55,12 +55,15 @@ import org.jetbrains.kotlin.ir.types.* import org.jetbrains.kotlin.ir.types.impl.IrErrorTypeImpl import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.ir.util.functions +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.name.SpecialNames import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.psi +import org.jetbrains.kotlin.psi.KtParameter import org.jetbrains.kotlin.psi.KtQualifiedExpression import org.jetbrains.kotlin.psi.psiUtil.endOffset import org.jetbrains.kotlin.psi.psiUtil.startOffsetSkippingComments +import org.jetbrains.kotlin.resolve.calls.util.isSingleUnderscore import org.jetbrains.kotlin.types.ConstantValueKind import org.jetbrains.kotlin.types.Variance import org.jetbrains.kotlin.util.OperatorNameConventions @@ -488,16 +491,18 @@ internal fun IrDeclarationParent.declareThisReceiverParameter( thisType: IrType, thisOrigin: IrDeclarationOrigin, startOffset: Int = this.startOffset, - endOffset: Int = this.endOffset -): IrValueParameter = - symbolTable.irFactory.createValueParameter( + endOffset: Int = this.endOffset, + name: Name = SpecialNames.THIS +): IrValueParameter { + return symbolTable.irFactory.createValueParameter( startOffset, endOffset, thisOrigin, IrValueParameterSymbolImpl(), - SpecialNames.THIS, UNDEFINED_PARAMETER_INDEX, thisType, + name, UNDEFINED_PARAMETER_INDEX, thisType, varargElementType = null, isCrossinline = false, isNoinline = false, isHidden = false, isAssignable = false ).apply { this.parent = this@declareThisReceiverParameter } +} fun FirClass.irOrigin(firProvider: FirProvider): IrDeclarationOrigin = when { firProvider.getFirClassifierContainerFileIfAny(symbol) != null -> IrDeclarationOrigin.DEFINED @@ -615,6 +620,15 @@ fun FirSession.createFilesWithGeneratedDeclarations(): List { fun FirDeclaration?.computeIrOrigin(predefinedOrigin: IrDeclarationOrigin? = null): IrDeclarationOrigin { return predefinedOrigin ?: (this?.origin as? FirDeclarationOrigin.Plugin)?.let { IrPluginDeclarationOrigin(it.key) } + ?: ((this as? FirValueParameter)?.source.psi as? KtParameter)?.let { + if (it.isSingleUnderscore) { + IrDeclarationOrigin.UNDERSCORE_PARAMETER + } else if (it.destructuringDeclaration != null) { + IrDeclarationOrigin.DESTRUCTURED_OBJECT_PARAMETER + } else { + null + } + } ?: IrDeclarationOrigin.DEFINED } diff --git a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt index 939b115b0ea..5c8be33e211 100644 --- a/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt +++ b/compiler/fir/fir2ir/src/org/jetbrains/kotlin/fir/backend/Fir2IrDeclarationStorage.kt @@ -338,12 +338,17 @@ class Fir2IrDeclarationStorage( else parentPropertyReceiverType if (receiverTypeRef != null) { extensionReceiverParameter = receiverTypeRef.convertWithOffsets { startOffset, endOffset -> + val name = (function as? FirAnonymousFunction)?.label?.name?.let { + val suffix = it.takeIf(Name::isValidIdentifier) ?: "\$receiver" + Name.identifier("\$this\$$suffix") + } ?: SpecialNames.THIS declareThisReceiverParameter( symbolTable, thisType = receiverTypeRef.toIrType(typeContext), thisOrigin = thisOrigin, startOffset = startOffset, - endOffset = endOffset + endOffset = endOffset, + name = name ) } } diff --git a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java index 7ae24515fde..ef170775ceb 100644 --- a/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java +++ b/compiler/fir/fir2ir/tests-gen/org/jetbrains/kotlin/test/runners/ir/Fir2IrTextTestGenerated.java @@ -2462,6 +2462,12 @@ public class Fir2IrTextTestGenerated extends AbstractFir2IrTextTest { runTest("compiler/testData/ir/irText/lambdas/justLambda.kt"); } + @Test + @TestMetadata("lambdaReturningUnit.kt") + public void testLambdaReturningUnit() throws Exception { + runTest("compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt"); + } + @Test @TestMetadata("localFunction.kt") public void testLocalFunction() throws Exception { diff --git a/compiler/testData/codegen/box/fir/noSymbolForIntRangeIterator.fir.ir.txt b/compiler/testData/codegen/box/fir/noSymbolForIntRangeIterator.fir.ir.txt index 66126afe3e0..b092df3d6de 100644 --- a/compiler/testData/codegen/box/fir/noSymbolForIntRangeIterator.fir.ir.txt +++ b/compiler/testData/codegen/box/fir/noSymbolForIntRangeIterator.fir.ir.txt @@ -69,7 +69,7 @@ FILE fqName: fileName:/noSymbolForIntRangeIterator.kt CALL 'public final fun buildString (builderAction: @[ExtensionFunctionType] kotlin.Function1): kotlin.String [inline] declared in kotlin.text.StringsKt' type=kotlin.String origin=null builderAction: FUN_EXPR type=kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:java.lang.StringBuilder) returnType:kotlin.Unit - $receiver: VALUE_PARAMETER name: type:java.lang.StringBuilder + $receiver: VALUE_PARAMETER name:$this$buildString type:java.lang.StringBuilder BLOCK_BODY BLOCK type=kotlin.Unit origin=FOR_LOOP VAR FOR_LOOP_ITERATOR name:tmp_2 type:kotlin.collections.IntIterator [val] @@ -85,7 +85,7 @@ FILE fqName: fileName:/noSymbolForIntRangeIterator.kt CALL 'public final fun next (): kotlin.Int [operator] declared in kotlin.collections.IntIterator' type=kotlin.Int origin=FOR_LOOP_NEXT $this: GET_VAR 'val tmp_2: kotlin.collections.IntIterator [val] declared in .test.localFunc.' type=kotlin.collections.IntIterator origin=null CALL 'public final fun appendLine (value: kotlin.String?): java.lang.StringBuilder [inline] declared in kotlin.text.StringsKt' type=java.lang.StringBuilder origin=null - $receiver: GET_VAR ': java.lang.StringBuilder declared in .test.localFunc.' type=java.lang.StringBuilder origin=null + $receiver: GET_VAR '$this$buildString: java.lang.StringBuilder declared in .test.localFunc.' type=java.lang.StringBuilder origin=null value: STRING_CONCATENATION type=kotlin.String CALL 'public final fun times (other: kotlin.Int): kotlin.Int [operator] declared in kotlin.Int' type=kotlin.Int origin=MUL $this: GET_VAR 'val i: kotlin.Int [val] declared in .test.localFunc' type=kotlin.Int origin=null diff --git a/compiler/testData/debug/localVariables/suspend/mergeLvt.kt b/compiler/testData/debug/localVariables/suspend/mergeLvt.kt index 4a0e4caf66e..6fef27fdd5b 100644 --- a/compiler/testData/debug/localVariables/suspend/mergeLvt.kt +++ b/compiler/testData/debug/localVariables/suspend/mergeLvt.kt @@ -41,7 +41,9 @@ suspend fun box() { // test.kt:16 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int, $this$extensionFun$iv$iv:AtomicInt=AtomicInt, $i$f$extensionFun:int=0:int // test.kt:20 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int // test.kt:21 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int, $i$a$-suspendCoroutineUninterceptedOrReturn-TestKt$suspendBar$2$iv:int=0:int +// EXPECTATIONS CLASSIC_FRONTEND // test.kt:22 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int, $i$a$-suspendCoroutineUninterceptedOrReturn-TestKt$suspendBar$2$iv:int=0:int +// EXPECTATIONS // test.kt:20 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int // test.kt:23 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null, $i$f$suspendBar:int=0:int // test.kt:26 box: $continuation:kotlin.coroutines.Continuation=TestKt$box$1, $result:java.lang.Object=null diff --git a/compiler/testData/ir/irText/classes/initValInLambda.fir.ir.txt b/compiler/testData/ir/irText/classes/initValInLambda.fir.ir.txt index 95468c94428..236ead7c1b4 100644 --- a/compiler/testData/ir/irText/classes/initValInLambda.fir.ir.txt +++ b/compiler/testData/ir/irText/classes/initValInLambda.fir.ir.txt @@ -22,7 +22,7 @@ FILE fqName: fileName:/initValInLambda.kt $receiver: CONST Int type=kotlin.Int value=1 block: FUN_EXPR type=kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.Int) returnType:kotlin.Unit - $receiver: VALUE_PARAMETER name: type:kotlin.Int + $receiver: VALUE_PARAMETER name:$this$run type:kotlin.Int BLOCK_BODY SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:x type:kotlin.Int visibility:private [final]' type=kotlin.Unit origin=null receiver: GET_VAR ': .TestInitValInLambdaCalledOnce declared in .TestInitValInLambdaCalledOnce' type=.TestInitValInLambdaCalledOnce origin=null diff --git a/compiler/testData/ir/irText/expressions/kt37570.fir.ir.txt b/compiler/testData/ir/irText/expressions/kt37570.fir.ir.txt index d7d0151f215..b448ab99eb9 100644 --- a/compiler/testData/ir/irText/expressions/kt37570.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/kt37570.fir.ir.txt @@ -26,11 +26,11 @@ FILE fqName: fileName:/kt37570.kt $receiver: CALL 'public final fun a (): kotlin.String declared in ' type=kotlin.String origin=null block: FUN_EXPR type=kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.String) returnType:kotlin.Unit - $receiver: VALUE_PARAMETER name: type:kotlin.String + $receiver: VALUE_PARAMETER name:$this$apply type:kotlin.String BLOCK_BODY SET_FIELD 'FIELD PROPERTY_BACKING_FIELD name:b type:kotlin.String visibility:private [final]' type=kotlin.Unit origin=null receiver: GET_VAR ': .A declared in .A' type=.A origin=null - value: GET_VAR ': kotlin.String declared in .A.' type=kotlin.String origin=null + value: GET_VAR '$this$apply: kotlin.String declared in .A.' type=kotlin.String 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 [operator] declared in kotlin.Any diff --git a/compiler/testData/ir/irText/expressions/kt37570.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt37570.fir.kt.txt index 76ba6c9c5c6..ed1901631b0 100644 --- a/compiler/testData/ir/irText/expressions/kt37570.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/kt37570.fir.kt.txt @@ -14,9 +14,10 @@ class A { init { a().apply(block = local fun String.() { - .#b = + .#b = $this$apply } ) /*~> Unit */ } } + diff --git a/compiler/testData/ir/irText/expressions/kt47082.fir.ir.txt b/compiler/testData/ir/irText/expressions/kt47082.fir.ir.txt index bed18a2041c..edeac2f00e0 100644 --- a/compiler/testData/ir/irText/expressions/kt47082.fir.ir.txt +++ b/compiler/testData/ir/irText/expressions/kt47082.fir.ir.txt @@ -74,14 +74,14 @@ FILE fqName: fileName:/kt47082.kt : R of .foo block: FUN_EXPR type=kotlin.Function1<.Derived, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.Derived) returnType:kotlin.Unit - $receiver: VALUE_PARAMETER name: type:.Derived + $receiver: VALUE_PARAMETER name:$this$produce type:.Derived BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public final fun toChannel (destination: C of .toChannel): C of .toChannel declared in ' type=.Derived origin=null : R of .foo : .Derived $receiver: GET_VAR 'r: .Receiver.foo> declared in .foo' type=.Receiver.foo> origin=null - destination: GET_VAR ': .Derived declared in .foo.' type=.Derived origin=null + destination: GET_VAR '$this$produce: .Derived declared in .foo.' type=.Derived origin=null FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='public final fun box (): kotlin.String declared in ' diff --git a/compiler/testData/ir/irText/expressions/kt47082.fir.kt.txt b/compiler/testData/ir/irText/expressions/kt47082.fir.kt.txt index 587511dcc94..f3b306a7ae3 100644 --- a/compiler/testData/ir/irText/expressions/kt47082.fir.kt.txt +++ b/compiler/testData/ir/irText/expressions/kt47082.fir.kt.txt @@ -20,7 +20,7 @@ fun > Receiver.toChannel(destination: C): C { fun foo(r: Receiver): R { return produce(block = local fun Derived.() { - r.toChannel>(destination = ) /*~> Unit */ + r.toChannel>(destination = $this$produce) /*~> Unit */ } ) } @@ -28,3 +28,4 @@ fun foo(r: Receiver): R { fun box(): String { return "OK" } + diff --git a/compiler/testData/ir/irText/firProblems/AllCandidates.fir.ir.txt b/compiler/testData/ir/irText/firProblems/AllCandidates.fir.ir.txt index 6a07b6a4be9..765733157d8 100644 --- a/compiler/testData/ir/irText/firProblems/AllCandidates.fir.ir.txt +++ b/compiler/testData/ir/irText/firProblems/AllCandidates.fir.ir.txt @@ -61,10 +61,10 @@ FILE fqName: fileName:/AllCandidates.kt : @[FlexibleNullability] A of .allCandidatesResult? block: FUN_EXPR type=kotlin.Function1<@[FlexibleNullability] .OverloadResolutionResultsImpl<@[FlexibleNullability] A of .allCandidatesResult?>?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:@[FlexibleNullability] .OverloadResolutionResultsImpl<@[FlexibleNullability] A of .allCandidatesResult?>?) returnType:kotlin.Unit - $receiver: VALUE_PARAMETER name: type:@[FlexibleNullability] .OverloadResolutionResultsImpl<@[FlexibleNullability] A of .allCandidatesResult?>? + $receiver: VALUE_PARAMETER name:$this$apply type:@[FlexibleNullability] .OverloadResolutionResultsImpl<@[FlexibleNullability] A of .allCandidatesResult?>? BLOCK_BODY CALL 'public open fun setAllCandidates (allCandidates: @[FlexibleNullability] kotlin.collections.Collection<@[FlexibleNullability] .ResolvedCall<@[FlexibleNullability] D of .OverloadResolutionResultsImpl?>?>?): kotlin.Unit declared in .OverloadResolutionResultsImpl' type=kotlin.Unit origin=EQ - $this: GET_VAR ': @[FlexibleNullability] .OverloadResolutionResultsImpl<@[FlexibleNullability] A of .allCandidatesResult?>? declared in .allCandidatesResult.' type=@[FlexibleNullability] .OverloadResolutionResultsImpl<@[FlexibleNullability] A of .allCandidatesResult?>? origin=null + $this: GET_VAR '$this$apply: @[FlexibleNullability] .OverloadResolutionResultsImpl<@[FlexibleNullability] A of .allCandidatesResult?>? declared in .allCandidatesResult.' type=@[FlexibleNullability] .OverloadResolutionResultsImpl<@[FlexibleNullability] A of .allCandidatesResult?>? origin=null allCandidates: CALL 'public final fun map (transform: kotlin.Function1): kotlin.collections.List [inline] declared in kotlin.collections.CollectionsKt' type=kotlin.collections.List<.ResolvedCall.allCandidatesResult>> origin=null : .MyCandidate : .ResolvedCall.allCandidatesResult> diff --git a/compiler/testData/ir/irText/firProblems/AllCandidates.fir.kt.txt b/compiler/testData/ir/irText/firProblems/AllCandidates.fir.kt.txt index 5ac3b9c58f6..143474446d5 100644 --- a/compiler/testData/ir/irText/firProblems/AllCandidates.fir.kt.txt +++ b/compiler/testData/ir/irText/firProblems/AllCandidates.fir.kt.txt @@ -22,10 +22,11 @@ class MyCandidate { private fun allCandidatesResult(allCandidates: Collection): @FlexibleNullability OverloadResolutionResultsImpl<@FlexibleNullability A?>? { return nameNotFound<@FlexibleNullability A?>().apply<@FlexibleNullability OverloadResolutionResultsImpl<@FlexibleNullability A?>?>(block = local fun @FlexibleNullability OverloadResolutionResultsImpl<@FlexibleNullability A?>?.() { - .setAllCandidates(allCandidates = allCandidates.map>(transform = local fun (it: MyCandidate): ResolvedCall { + $this$apply.setAllCandidates(allCandidates = allCandidates.map>(transform = local fun (it: MyCandidate): ResolvedCall { return it.() as ResolvedCall } )) } ) } + diff --git a/compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.fir.ir.txt b/compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.fir.ir.txt index 1eb1f603a16..2f960d9f8bd 100644 --- a/compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.fir.ir.txt +++ b/compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.fir.ir.txt @@ -622,31 +622,31 @@ FILE fqName: fileName:/typeVariableAfterBuildMap.kt : kotlin.Int builderAction: FUN_EXPR type=kotlin.Function1.Visibility, kotlin.Int>, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.collections.MutableMap<.Visibility, kotlin.Int>) returnType:kotlin.Unit - $receiver: VALUE_PARAMETER name: type:kotlin.collections.MutableMap<.Visibility, kotlin.Int> + $receiver: VALUE_PARAMETER name:$this$buildMap type:kotlin.collections.MutableMap<.Visibility, kotlin.Int> BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public abstract fun put (key: K of kotlin.collections.MutableMap, value: V of kotlin.collections.MutableMap): V of kotlin.collections.MutableMap? declared in kotlin.collections.MutableMap' type=kotlin.Int? origin=null - $this: GET_VAR ': kotlin.collections.MutableMap<.Visibility, kotlin.Int> declared in .Visibilities.ORDERED_VISIBILITIES.' type=kotlin.collections.MutableMap<.Visibility, kotlin.Int> origin=null + $this: GET_VAR '$this$buildMap: kotlin.collections.MutableMap<.Visibility, kotlin.Int> declared in .Visibilities.ORDERED_VISIBILITIES.' type=kotlin.collections.MutableMap<.Visibility, kotlin.Int> origin=null key: GET_OBJECT 'CLASS OBJECT name:PrivateToThis modality:FINAL visibility:public superTypes:[.Visibility]' type=.Visibilities.PrivateToThis value: CONST Int type=kotlin.Int value=0 TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public abstract fun put (key: K of kotlin.collections.MutableMap, value: V of kotlin.collections.MutableMap): V of kotlin.collections.MutableMap? declared in kotlin.collections.MutableMap' type=kotlin.Int? origin=null - $this: GET_VAR ': kotlin.collections.MutableMap<.Visibility, kotlin.Int> declared in .Visibilities.ORDERED_VISIBILITIES.' type=kotlin.collections.MutableMap<.Visibility, kotlin.Int> origin=null + $this: GET_VAR '$this$buildMap: kotlin.collections.MutableMap<.Visibility, kotlin.Int> declared in .Visibilities.ORDERED_VISIBILITIES.' type=kotlin.collections.MutableMap<.Visibility, kotlin.Int> origin=null key: GET_OBJECT 'CLASS OBJECT name:Private modality:FINAL visibility:public superTypes:[.Visibility]' type=.Visibilities.Private value: CONST Int type=kotlin.Int value=0 TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public abstract fun put (key: K of kotlin.collections.MutableMap, value: V of kotlin.collections.MutableMap): V of kotlin.collections.MutableMap? declared in kotlin.collections.MutableMap' type=kotlin.Int? origin=null - $this: GET_VAR ': kotlin.collections.MutableMap<.Visibility, kotlin.Int> declared in .Visibilities.ORDERED_VISIBILITIES.' type=kotlin.collections.MutableMap<.Visibility, kotlin.Int> origin=null + $this: GET_VAR '$this$buildMap: kotlin.collections.MutableMap<.Visibility, kotlin.Int> declared in .Visibilities.ORDERED_VISIBILITIES.' type=kotlin.collections.MutableMap<.Visibility, kotlin.Int> origin=null key: GET_OBJECT 'CLASS OBJECT name:Internal modality:FINAL visibility:public superTypes:[.Visibility]' type=.Visibilities.Internal value: CONST Int type=kotlin.Int value=1 TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public abstract fun put (key: K of kotlin.collections.MutableMap, value: V of kotlin.collections.MutableMap): V of kotlin.collections.MutableMap? declared in kotlin.collections.MutableMap' type=kotlin.Int? origin=null - $this: GET_VAR ': kotlin.collections.MutableMap<.Visibility, kotlin.Int> declared in .Visibilities.ORDERED_VISIBILITIES.' type=kotlin.collections.MutableMap<.Visibility, kotlin.Int> origin=null + $this: GET_VAR '$this$buildMap: kotlin.collections.MutableMap<.Visibility, kotlin.Int> declared in .Visibilities.ORDERED_VISIBILITIES.' type=kotlin.collections.MutableMap<.Visibility, kotlin.Int> origin=null key: GET_OBJECT 'CLASS OBJECT name:Protected modality:FINAL visibility:public superTypes:[.Visibility]' type=.Visibilities.Protected value: CONST Int type=kotlin.Int value=1 TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public abstract fun put (key: K of kotlin.collections.MutableMap, value: V of kotlin.collections.MutableMap): V of kotlin.collections.MutableMap? declared in kotlin.collections.MutableMap' type=kotlin.Int? origin=null - $this: GET_VAR ': kotlin.collections.MutableMap<.Visibility, kotlin.Int> declared in .Visibilities.ORDERED_VISIBILITIES.' type=kotlin.collections.MutableMap<.Visibility, kotlin.Int> origin=null + $this: GET_VAR '$this$buildMap: kotlin.collections.MutableMap<.Visibility, kotlin.Int> declared in .Visibilities.ORDERED_VISIBILITIES.' type=kotlin.collections.MutableMap<.Visibility, kotlin.Int> origin=null key: GET_OBJECT 'CLASS OBJECT name:Public modality:FINAL visibility:public superTypes:[.Visibility]' type=.Visibilities.Public value: CONST Int type=kotlin.Int value=2 FUN DEFAULT_PROPERTY_ACCESSOR name: visibility:private modality:FINAL <> ($this:.Visibilities) returnType:kotlin.collections.Map<.Visibility, kotlin.Int> diff --git a/compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.fir.kt.txt b/compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.fir.kt.txt index 208bad8f60e..d6b34abc806 100644 --- a/compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.fir.kt.txt +++ b/compiler/testData/ir/irText/firProblems/typeVariableAfterBuildMap.fir.kt.txt @@ -163,13 +163,14 @@ object Visibilities { private val ORDERED_VISIBILITIES: Map field = buildMap(builderAction = local fun MutableMap.() { - .put(key = PrivateToThis, value = 0) /*~> Unit */ - .put(key = Private, value = 0) /*~> Unit */ - .put(key = Internal, value = 1) /*~> Unit */ - .put(key = Protected, value = 1) /*~> Unit */ - .put(key = Public, value = 2) /*~> Unit */ + $this$buildMap.put(key = PrivateToThis, value = 0) /*~> Unit */ + $this$buildMap.put(key = Private, value = 0) /*~> Unit */ + $this$buildMap.put(key = Internal, value = 1) /*~> Unit */ + $this$buildMap.put(key = Protected, value = 1) /*~> Unit */ + $this$buildMap.put(key = Public, value = 2) /*~> Unit */ } ) private get } + diff --git a/compiler/testData/ir/irText/lambdas/destructuringInLambda.fir.ir.txt b/compiler/testData/ir/irText/lambdas/destructuringInLambda.fir.ir.txt index 1f92d261a0c..dcdbccb9208 100644 --- a/compiler/testData/ir/irText/lambdas/destructuringInLambda.fir.ir.txt +++ b/compiler/testData/ir/irText/lambdas/destructuringInLambda.fir.ir.txt @@ -140,7 +140,7 @@ FILE fqName: fileName:/destructuringInLambda.kt EXPRESSION_BODY FUN_EXPR type=kotlin.Function1<.A, kotlin.Int> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> (:.A) returnType:kotlin.Int - VALUE_PARAMETER name: index:0 type:.A + VALUE_PARAMETER DESTRUCTURED_OBJECT_PARAMETER name: index:0 type:.A BLOCK_BODY VAR name:y type:kotlin.Int [val] CALL 'public final fun component2 (): kotlin.Int [operator] declared in .A' type=kotlin.Int origin=COMPONENT_N(index=2) diff --git a/compiler/testData/ir/irText/lambdas/extensionLambda.fir.ir.txt b/compiler/testData/ir/irText/lambdas/extensionLambda.fir.ir.txt index 22aea224ecd..45026b02efd 100644 --- a/compiler/testData/ir/irText/lambdas/extensionLambda.fir.ir.txt +++ b/compiler/testData/ir/irText/lambdas/extensionLambda.fir.ir.txt @@ -8,8 +8,8 @@ FILE fqName: fileName:/extensionLambda.kt $receiver: CONST String type=kotlin.String value="42" block: FUN_EXPR type=kotlin.Function1 origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:kotlin.String) returnType:kotlin.Int - $receiver: VALUE_PARAMETER name: type:kotlin.String + $receiver: VALUE_PARAMETER name:$this$run type:kotlin.String BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun (): kotlin.Int declared in .test1' CALL 'public open fun (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=GET_PROPERTY - $this: GET_VAR ': kotlin.String declared in .test1.' type=kotlin.String origin=null + $this: GET_VAR '$this$run: kotlin.String declared in .test1.' type=kotlin.String origin=null diff --git a/compiler/testData/ir/irText/lambdas/extensionLambda.fir.kt.txt b/compiler/testData/ir/irText/lambdas/extensionLambda.fir.kt.txt index 46b75238fa5..b353ca3f2b1 100644 --- a/compiler/testData/ir/irText/lambdas/extensionLambda.fir.kt.txt +++ b/compiler/testData/ir/irText/lambdas/extensionLambda.fir.kt.txt @@ -1,6 +1,7 @@ fun test1(): Int { return "42".run(block = local fun String.(): Int { - return .() + return $this$run.() } ) } + diff --git a/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.fir.ir.txt b/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.fir.ir.txt new file mode 100644 index 00000000000..de94d045322 --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.fir.ir.txt @@ -0,0 +1,15 @@ +FILE fqName: fileName:/lambdaReturningUnit.kt + FUN name:flaf visibility:public modality:FINAL <> (block:kotlin.Function0) returnType:kotlin.Unit [inline] + VALUE_PARAMETER name:block index:0 type:kotlin.Function0 + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.Any? origin=INVOKE + $this: GET_VAR 'block: kotlin.Function0 declared in .flaf' type=kotlin.Function0 origin=VARIABLE_AS_FUNCTION + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.Unit [suspend] + BLOCK_BODY + CALL 'public final fun flaf (block: kotlin.Function0): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Any? + BLOCK_BODY + RETURN type=kotlin.Nothing from='local final fun (): kotlin.Any? declared in .box' + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit diff --git a/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.fir.kt.txt b/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.fir.kt.txt new file mode 100644 index 00000000000..7f77b344a30 --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.fir.kt.txt @@ -0,0 +1,10 @@ +inline fun flaf(block: Function0) { + block.invoke() /*~> Unit */ +} + +suspend fun box() { + flaf(block = local fun (): Any? { + return Unit + } +) +} diff --git a/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.ir.txt b/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.ir.txt new file mode 100644 index 00000000000..f5440d0b590 --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.ir.txt @@ -0,0 +1,14 @@ +FILE fqName: fileName:/lambdaReturningUnit.kt + FUN name:flaf visibility:public modality:FINAL <> (block:kotlin.Function0) returnType:kotlin.Unit [inline] + VALUE_PARAMETER name:block index:0 type:kotlin.Function0 + BLOCK_BODY + TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit + CALL 'public abstract fun invoke (): R of kotlin.Function0 [operator] declared in kotlin.Function0' type=kotlin.Any? origin=INVOKE + $this: GET_VAR 'block: kotlin.Function0 declared in .flaf' type=kotlin.Function0 origin=VARIABLE_AS_FUNCTION + FUN name:box visibility:public modality:FINAL <> () returnType:kotlin.Unit [suspend] + BLOCK_BODY + CALL 'public final fun flaf (block: kotlin.Function0): kotlin.Unit [inline] declared in ' type=kotlin.Unit origin=null + block: FUN_EXPR type=kotlin.Function0 origin=LAMBDA + FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit + BLOCK_BODY + GET_OBJECT 'CLASS IR_EXTERNAL_DECLARATION_STUB OBJECT name:Unit modality:FINAL visibility:public superTypes:[kotlin.Any]' type=kotlin.Unit diff --git a/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt b/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt new file mode 100644 index 00000000000..fefa6a759ec --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt @@ -0,0 +1,12 @@ +// With FIR the type of the lambda in box is () -> Any? +// With old frontend the type of the lambda is () -> Unit + +inline fun flaf(block: () -> Any?) { + block() +} + +suspend fun box() { + flaf { + Unit + } +} diff --git a/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt.txt b/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt.txt new file mode 100644 index 00000000000..0ba7d56ae4d --- /dev/null +++ b/compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt.txt @@ -0,0 +1,11 @@ +inline fun flaf(block: Function0) { + block.invoke() /*~> Unit */ +} + +suspend fun box() { + flaf(block = local fun () { + Unit + } +) +} + diff --git a/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.ir.txt b/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.ir.txt index 382de868b94..1a04f896442 100644 --- a/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.ir.txt +++ b/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.ir.txt @@ -92,7 +92,7 @@ FILE fqName: fileName:/multipleImplicitReceivers.kt receiver: GET_OBJECT 'CLASS OBJECT name:A modality:FINAL visibility:public superTypes:[kotlin.Any]' type=.A block: FUN_EXPR type=kotlin.Function1<.A, kotlin.Int> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.A) returnType:kotlin.Int - $receiver: VALUE_PARAMETER name: type:.A + $receiver: VALUE_PARAMETER name:$this$with type:.A BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun (): kotlin.Int declared in .test' CALL 'public final fun with (receiver: T of kotlin.StandardKt.with, block: @[ExtensionFunctionType] kotlin.Function1): R of kotlin.StandardKt.with [inline] declared in kotlin.StandardKt' type=kotlin.Int origin=null @@ -101,7 +101,7 @@ FILE fqName: fileName:/multipleImplicitReceivers.kt receiver: GET_VAR 'fooImpl: .IFoo declared in .test' type=.IFoo origin=null block: FUN_EXPR type=kotlin.Function1<.IFoo, kotlin.Int> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.IFoo) returnType:kotlin.Int - $receiver: VALUE_PARAMETER name: type:.IFoo + $receiver: VALUE_PARAMETER name:$this$with type:.IFoo BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun (): kotlin.Int declared in .test.' CALL 'public final fun with (receiver: T of kotlin.StandardKt.with, block: @[ExtensionFunctionType] kotlin.Function1): R of kotlin.StandardKt.with [inline] declared in kotlin.StandardKt' type=kotlin.Int origin=null @@ -110,11 +110,11 @@ FILE fqName: fileName:/multipleImplicitReceivers.kt receiver: GET_VAR 'invokeImpl: .IInvoke declared in .test' type=.IInvoke origin=null block: FUN_EXPR type=kotlin.Function1<.IInvoke, kotlin.Int> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.IInvoke) returnType:kotlin.Int - $receiver: VALUE_PARAMETER name: type:.IInvoke + $receiver: VALUE_PARAMETER name:$this$with type:.IInvoke BLOCK_BODY RETURN type=kotlin.Nothing from='local final fun (): kotlin.Int declared in .test..' CALL 'public open fun invoke (): kotlin.Int [operator] declared in .IInvoke' type=kotlin.Int origin=null - $this: GET_VAR ': .IInvoke declared in .test...' type=.IInvoke origin=null + $this: GET_VAR '$this$with: .IInvoke declared in .test...' type=.IInvoke origin=null $receiver: CALL 'public open fun (): .B declared in .IFoo' type=.B origin=GET_PROPERTY - $this: GET_VAR ': .IFoo declared in .test..' type=.IFoo origin=null - $receiver: GET_VAR ': .A declared in .test.' type=.A origin=null + $this: GET_VAR '$this$with: .IFoo declared in .test..' type=.IFoo origin=null + $receiver: GET_VAR '$this$with: .A declared in .test.' type=.A origin=null diff --git a/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.kt.txt b/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.kt.txt index ebb433fa9a2..c44b81ee74d 100644 --- a/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.kt.txt +++ b/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.kt.txt @@ -35,7 +35,7 @@ fun test(fooImpl: IFoo, invokeImpl: IInvoke) { with(receiver = A, block = local fun A.(): Int { return with(receiver = fooImpl, block = local fun IFoo.(): Int { return with(receiver = invokeImpl, block = local fun IInvoke.(): Int { - return (, (, ).()).invoke() + return ($this$with, ($this$with, $this$with).()).invoke() } ) } @@ -43,3 +43,4 @@ fun test(fooImpl: IFoo, invokeImpl: IInvoke) { } ) /*~> Unit */ } + diff --git a/compiler/testData/ir/irText/stubs/builtinMap.fir.ir.txt b/compiler/testData/ir/irText/stubs/builtinMap.fir.ir.txt index c081da912c4..d54490ee6a5 100644 --- a/compiler/testData/ir/irText/stubs/builtinMap.fir.ir.txt +++ b/compiler/testData/ir/irText/stubs/builtinMap.fir.ir.txt @@ -24,11 +24,11 @@ FILE fqName: fileName:/builtinMap.kt p0: GET_VAR ': kotlin.collections.Map.plus, V1 of .plus> declared in .plus' type=kotlin.collections.Map.plus, V1 of .plus> origin=null block: FUN_EXPR type=kotlin.Function1.plus?, @[FlexibleNullability] V1 of .plus?>, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:java.util.LinkedHashMap<@[FlexibleNullability] K1 of .plus?, @[FlexibleNullability] V1 of .plus?>) returnType:kotlin.Unit - $receiver: VALUE_PARAMETER name: type:java.util.LinkedHashMap<@[FlexibleNullability] K1 of .plus?, @[FlexibleNullability] V1 of .plus?> + $receiver: VALUE_PARAMETER name:$this$apply type:java.util.LinkedHashMap<@[FlexibleNullability] K1 of .plus?, @[FlexibleNullability] V1 of .plus?> BLOCK_BODY TYPE_OP type=kotlin.Unit origin=IMPLICIT_COERCION_TO_UNIT typeOperand=kotlin.Unit CALL 'public open fun put (p0: @[FlexibleNullability] K of java.util.LinkedHashMap?, p1: @[FlexibleNullability] V of java.util.LinkedHashMap?): V of java.util.LinkedHashMap? [fake_override] declared in java.util.LinkedHashMap' type=V1 of .plus? origin=null - $this: GET_VAR ': java.util.LinkedHashMap<@[FlexibleNullability] K1 of .plus?, @[FlexibleNullability] V1 of .plus?> declared in .plus.' type=java.util.LinkedHashMap<@[FlexibleNullability] K1 of .plus?, @[FlexibleNullability] V1 of .plus?> origin=null + $this: GET_VAR '$this$apply: java.util.LinkedHashMap<@[FlexibleNullability] K1 of .plus?, @[FlexibleNullability] V1 of .plus?> declared in .plus.' type=java.util.LinkedHashMap<@[FlexibleNullability] K1 of .plus?, @[FlexibleNullability] V1 of .plus?> origin=null p0: CALL 'public final fun (): A of kotlin.Pair declared in kotlin.Pair' type=K1 of .plus origin=GET_PROPERTY $this: GET_VAR 'pair: kotlin.Pair.plus, V1 of .plus> declared in .plus' type=kotlin.Pair.plus, V1 of .plus> origin=null p1: CALL 'public final fun (): B of kotlin.Pair declared in kotlin.Pair' type=V1 of .plus origin=GET_PROPERTY diff --git a/compiler/testData/ir/irText/stubs/builtinMap.fir.kt.txt b/compiler/testData/ir/irText/stubs/builtinMap.fir.kt.txt index a43473a82d0..8c96621b011 100644 --- a/compiler/testData/ir/irText/stubs/builtinMap.fir.kt.txt +++ b/compiler/testData/ir/irText/stubs/builtinMap.fir.kt.txt @@ -2,8 +2,9 @@ fun Map.plus(pair: Pair): Map return when { .isEmpty() -> mapOf(pair = pair) else -> LinkedHashMap<@FlexibleNullability K1?, @FlexibleNullability V1?>(p0 = ).apply>(block = local fun LinkedHashMap<@FlexibleNullability K1?, @FlexibleNullability V1?>.() { - .put(p0 = pair.(), p1 = pair.()) /*~> Unit */ + $this$apply.put(p0 = pair.(), p1 = pair.()) /*~> Unit */ } ) } } + diff --git a/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.ir.txt b/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.ir.txt index 7798f101e28..a743ccd9e03 100644 --- a/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.ir.txt +++ b/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.ir.txt @@ -12,19 +12,19 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt : R of .scopedFlow block: FUN_EXPR type=kotlin.coroutines.SuspendFunction1<.FlowCollector.scopedFlow>, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.FlowCollector.scopedFlow>) returnType:kotlin.Unit [suspend] - $receiver: VALUE_PARAMETER name: type:.FlowCollector.scopedFlow> + $receiver: VALUE_PARAMETER name:$this$flow type:.FlowCollector.scopedFlow> BLOCK_BODY VAR name:collector type:.FlowCollector.scopedFlow> [val] - GET_VAR ': .FlowCollector.scopedFlow> declared in .scopedFlow.' type=.FlowCollector.scopedFlow> origin=null + GET_VAR '$this$flow: .FlowCollector.scopedFlow> declared in .scopedFlow.' type=.FlowCollector.scopedFlow> origin=null CALL 'public final fun flowScope (block: @[ExtensionFunctionType] kotlin.coroutines.SuspendFunction1<.CoroutineScope, R of .flowScope>): R of .flowScope [suspend] declared in ' type=kotlin.Unit origin=null : kotlin.Unit block: FUN_EXPR type=kotlin.coroutines.SuspendFunction1<.CoroutineScope, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.CoroutineScope) returnType:kotlin.Unit [suspend] - $receiver: VALUE_PARAMETER name: type:.CoroutineScope + $receiver: VALUE_PARAMETER name:$this$flowScope type:.CoroutineScope BLOCK_BODY CALL 'public abstract fun invoke (p1: P1 of kotlin.coroutines.SuspendFunction2, p2: P2 of kotlin.coroutines.SuspendFunction2): R of kotlin.coroutines.SuspendFunction2 [suspend,operator] declared in kotlin.coroutines.SuspendFunction2' type=kotlin.Unit origin=null $this: GET_VAR 'block: @[ExtensionFunctionType] kotlin.coroutines.SuspendFunction2<.CoroutineScope, .FlowCollector.scopedFlow>, kotlin.Unit> declared in .scopedFlow' type=@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction2<.CoroutineScope, .FlowCollector.scopedFlow>, kotlin.Unit> origin=VARIABLE_AS_FUNCTION - p1: GET_VAR ': .CoroutineScope declared in .scopedFlow..' type=.CoroutineScope origin=null + p1: GET_VAR '$this$flowScope: .CoroutineScope declared in .scopedFlow..' type=.CoroutineScope origin=null p2: GET_VAR 'val collector: .FlowCollector.scopedFlow> [val] declared in .scopedFlow.' type=.FlowCollector.scopedFlow> origin=null FUN name:onCompletion visibility:public modality:FINAL ($receiver:.Flow.onCompletion>, action:@[ExtensionFunctionType] kotlin.coroutines.SuspendFunction2<.FlowCollector.onCompletion>, @[ParameterName(name = 'cause')] kotlin.Throwable?, kotlin.Unit>) returnType:.Flow.onCompletion> TYPE_PARAMETER name:T index:0 variance: superTypes:[kotlin.Any?] @@ -36,12 +36,12 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt : T of .onCompletion block: FUN_EXPR type=kotlin.coroutines.SuspendFunction1<.FlowCollector.onCompletion>, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.FlowCollector.onCompletion>) returnType:kotlin.Unit [suspend] - $receiver: VALUE_PARAMETER name: type:.FlowCollector.onCompletion> + $receiver: VALUE_PARAMETER name:$this$unsafeFlow type:.FlowCollector.onCompletion> BLOCK_BODY VAR name:safeCollector type:.SafeCollector.onCompletion> [val] CONSTRUCTOR_CALL 'public constructor (collector: .FlowCollector.SafeCollector>) [primary] declared in .SafeCollector' type=.SafeCollector.onCompletion> origin=null : T of .onCompletion - collector: GET_VAR ': .FlowCollector.onCompletion> declared in .onCompletion.' type=.FlowCollector.onCompletion> origin=null + collector: GET_VAR '$this$unsafeFlow: .FlowCollector.onCompletion> declared in .onCompletion.' type=.FlowCollector.onCompletion> origin=null CALL 'public final fun invokeSafely (action: @[ExtensionFunctionType] kotlin.coroutines.SuspendFunction2<.FlowCollector.invokeSafely>, @[ParameterName(name = 'cause')] kotlin.Throwable?, kotlin.Unit>): kotlin.Unit [suspend] declared in ' type=kotlin.Unit origin=null : T of .onCompletion $receiver: GET_VAR 'val safeCollector: .SafeCollector.onCompletion> [val] declared in .onCompletion.' type=.SafeCollector.onCompletion> origin=null @@ -74,7 +74,7 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt $receiver: GET_VAR ': .Flow.onCompletion> declared in .onCompletion' type=.Flow.onCompletion> origin=null action: FUN_EXPR type=kotlin.coroutines.SuspendFunction2<.FlowCollector.onCompletion>, @[ParameterName(name = 'cause')] kotlin.Throwable?, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.FlowCollector.onCompletion>, it:@[ParameterName(name = 'cause')] kotlin.Throwable?) returnType:kotlin.Unit [suspend] - $receiver: VALUE_PARAMETER name: type:.FlowCollector.onCompletion> + $receiver: VALUE_PARAMETER name:$this$onCompletion type:.FlowCollector.onCompletion> VALUE_PARAMETER name:it index:0 type:@[ParameterName(name = 'cause')] kotlin.Throwable? BLOCK_BODY CALL 'public abstract fun invoke (p1: P1 of kotlin.coroutines.SuspendFunction1): R of kotlin.coroutines.SuspendFunction1 [suspend,operator] declared in kotlin.coroutines.SuspendFunction1' type=kotlin.Unit origin=null @@ -90,12 +90,12 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt $receiver: GET_VAR ': .CoroutineScope declared in .asFairChannel' type=.CoroutineScope origin=null block: FUN_EXPR type=kotlin.coroutines.SuspendFunction1<.ProducerScope, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.ProducerScope) returnType:kotlin.Unit [suspend] - $receiver: VALUE_PARAMETER name: type:.ProducerScope + $receiver: VALUE_PARAMETER name:$this$produce type:.ProducerScope BLOCK_BODY VAR name:channel type:.ChannelCoroutine [val] TYPE_OP type=.ChannelCoroutine origin=CAST typeOperand=.ChannelCoroutine CALL 'public abstract fun (): .SendChannel.ProducerScope> declared in .ProducerScope' type=.SendChannel origin=GET_PROPERTY - $this: GET_VAR ': .ProducerScope declared in .asFairChannel.' type=.ProducerScope origin=null + $this: GET_VAR '$this$produce: .ProducerScope declared in .asFairChannel.' type=.ProducerScope origin=null CALL 'public final fun collect (action: kotlin.coroutines.SuspendFunction1<@[ParameterName(name = 'value')] T of .collect, kotlin.Unit>): kotlin.Unit [inline,suspend] declared in ' type=kotlin.Unit origin=null : kotlin.Any? $receiver: GET_VAR 'flow: .Flow<*> declared in .asFairChannel' type=.Flow<*> origin=null @@ -128,7 +128,7 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt $receiver: GET_VAR ': .CoroutineScope declared in .asChannel' type=.CoroutineScope origin=null block: FUN_EXPR type=kotlin.coroutines.SuspendFunction1<.ProducerScope<@[ParameterName(name = 'value')] kotlin.Any>, kotlin.Unit> origin=LAMBDA FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> ($receiver:.ProducerScope<@[ParameterName(name = 'value')] kotlin.Any>) returnType:kotlin.Unit [suspend] - $receiver: VALUE_PARAMETER name: type:.ProducerScope<@[ParameterName(name = 'value')] kotlin.Any> + $receiver: VALUE_PARAMETER name:$this$produce type:.ProducerScope<@[ParameterName(name = 'value')] kotlin.Any> BLOCK_BODY CALL 'public final fun collect (action: kotlin.coroutines.SuspendFunction1<@[ParameterName(name = 'value')] T of .collect, kotlin.Unit>): kotlin.Unit [inline,suspend] declared in ' type=kotlin.Unit origin=null : kotlin.Any? @@ -140,7 +140,7 @@ FILE fqName: fileName:/castsInsideCoroutineInference.kt RETURN type=kotlin.Nothing from='local final fun (value: @[ParameterName(name = 'value')] kotlin.Any?): kotlin.Unit [suspend] declared in .asChannel.' CALL 'public abstract fun send (e: E of .SendChannel): kotlin.Unit [suspend] declared in .SendChannel' type=kotlin.Unit origin=null $this: CALL 'public abstract fun (): .SendChannel.ProducerScope> declared in .ProducerScope' type=.SendChannel<@[ParameterName(name = 'value')] kotlin.Any> origin=GET_PROPERTY - $this: GET_VAR ': .ProducerScope<@[ParameterName(name = 'value')] kotlin.Any> declared in .asChannel.' type=.ProducerScope<@[ParameterName(name = 'value')] kotlin.Any> origin=null + $this: GET_VAR '$this$produce: .ProducerScope<@[ParameterName(name = 'value')] kotlin.Any> declared in .asChannel.' type=.ProducerScope<@[ParameterName(name = 'value')] kotlin.Any> origin=null e: BLOCK type=@[ParameterName(name = 'value')] kotlin.Any origin=ELVIS VAR IR_TEMPORARY_VARIABLE name:tmp_1 type:@[ParameterName(name = 'value')] kotlin.Any? [val] GET_VAR 'value: @[ParameterName(name = 'value')] kotlin.Any? declared in .asChannel..' type=@[ParameterName(name = 'value')] kotlin.Any? origin=null diff --git a/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.kt.txt b/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.kt.txt index b5f21f95346..96ea9b1f064 100644 --- a/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.kt.txt +++ b/compiler/testData/ir/irText/types/castsInsideCoroutineInference.fir.kt.txt @@ -1,9 +1,9 @@ @OptIn(markerClass = [ExperimentalTypeInference::class]) fun scopedFlow(@BuilderInference block: @ExtensionFunctionType SuspendFunction2, Unit>): Flow { return flow(block = local suspend fun FlowCollector.() { - val collector: FlowCollector = + val collector: FlowCollector = $this$flow flowScope(block = local suspend fun CoroutineScope.() { - block.invoke(p1 = , p2 = collector) + block.invoke(p1 = $this$flowScope, p2 = collector) } ) } @@ -12,7 +12,7 @@ fun scopedFlow(@BuilderInference block: @ExtensionFunctionType Suspen fun Flow.onCompletion(action: @ExtensionFunctionType SuspendFunction2, @ParameterName(name = "cause") Throwable?, Unit>): Flow { return unsafeFlow(block = local suspend fun FlowCollector.() { - val safeCollector: SafeCollector = SafeCollector(collector = ) + val safeCollector: SafeCollector = SafeCollector(collector = $this$unsafeFlow) safeCollector.invokeSafely(action = action) } ) @@ -36,7 +36,7 @@ fun Flow.onCompletion(action: SuspendFunction1<@ParameterName(name private fun CoroutineScope.asFairChannel(flow: Flow<*>): ReceiveChannel { return .produce(block = local suspend fun ProducerScope.() { - val channel: ChannelCoroutine = .() as ChannelCoroutine + val channel: ChannelCoroutine = $this$produce.() as ChannelCoroutine flow.collect(action = local suspend fun (value: @ParameterName(name = "value") Any?) { return channel.sendFair(element = { // BLOCK val : @ParameterName(name = "value") Any? = value @@ -54,7 +54,7 @@ private fun CoroutineScope.asFairChannel(flow: Flow<*>): ReceiveChannel { private fun CoroutineScope.asChannel(flow: Flow<*>): ReceiveChannel { return .produce<@ParameterName(name = "value") Any>(block = local suspend fun ProducerScope<@ParameterName(name = "value") Any>.() { flow.collect(action = local suspend fun (value: @ParameterName(name = "value") Any?) { - return .().send(e = { // BLOCK + return $this$produce.().send(e = { // BLOCK val : @ParameterName(name = "value") Any? = value when { EQEQ(arg0 = , arg1 = null) -> Any() @@ -141,3 +141,4 @@ interface SendChannel { abstract suspend fun send(e: E) } + diff --git a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java index 21324fc91b2..51681a53842 100644 --- a/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java +++ b/compiler/tests-common-new/tests-gen/org/jetbrains/kotlin/test/runners/ir/IrTextTestGenerated.java @@ -2462,6 +2462,12 @@ public class IrTextTestGenerated extends AbstractIrTextTest { runTest("compiler/testData/ir/irText/lambdas/justLambda.kt"); } + @Test + @TestMetadata("lambdaReturningUnit.kt") + public void testLambdaReturningUnit() throws Exception { + runTest("compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt"); + } + @Test @TestMetadata("localFunction.kt") public void testLocalFunction() throws Exception { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DebugRunner.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DebugRunner.kt index 6d7fcf661a9..bbbb8fc1392 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DebugRunner.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/handlers/DebugRunner.kt @@ -11,6 +11,8 @@ import com.sun.jdi.request.EventRequest.SUSPEND_ALL import com.sun.jdi.request.StepRequest import com.sun.tools.jdi.SocketAttachingConnector import org.jetbrains.kotlin.test.TargetBackend +import org.jetbrains.kotlin.test.model.FrontendKind +import org.jetbrains.kotlin.test.model.FrontendKinds import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.JUnit5Assertions.assertEqualsToFile import org.jetbrains.kotlin.test.services.TestServices @@ -27,12 +29,15 @@ abstract class DebugRunner(testServices: TestServices) : JvmBoxRunner(testServic const val FORCE_STEP_INTO_MARKER = "// FORCE_STEP_INTO" const val JVM_EXPECTATIONS_MARKER = "$EXPECTATIONS_MARKER JVM" const val JVM_IR_EXPECTATIONS_MARKER = "$EXPECTATIONS_MARKER JVM_IR" + const val CLASSIC_FRONTEND_EXPECTATIONS_MARKER = "$EXPECTATIONS_MARKER CLASSIC_FRONTEND" + const val FIR_EXPECTATIONS_MARKER = "$EXPECTATIONS_MARKER FIR" val BOX_MAIN_FILE_CLASS_NAME = BOX_MAIN_FILE_NAME.replace(".kt", "Kt") } private var wholeFile = File("") private var backend = TargetBackend.JVM + private var frontend: FrontendKind<*> = FrontendKinds.ClassicFrontend abstract fun storeStep(loggedItems: ArrayList, event: Event) @@ -42,8 +47,9 @@ abstract class DebugRunner(testServices: TestServices) : JvmBoxRunner(testServic classPath: List, mainClassAndArguments: List ): Process { - // Extract target backend and the full test file used to extract test expectations. + // Extract target backend, frontend, and the full test file used to extract test expectations. backend = module.targetBackend ?: backend + frontend = module.frontendKind wholeFile = module.files.single { it.name == "test.kt" }.originalFile // Setup the java process to suspend waiting for debugging connection on a free port. @@ -187,6 +193,7 @@ abstract class DebugRunner(testServices: TestServices) : JvmBoxRunner(testServic } var currentBackend = TargetBackend.ANY + var currentFrontend = frontend for (line in lineIterator) { if (line.isEmpty()) { actual.add(line) @@ -198,11 +205,22 @@ abstract class DebugRunner(testServices: TestServices) : JvmBoxRunner(testServic EXPECTATIONS_MARKER -> TargetBackend.ANY JVM_EXPECTATIONS_MARKER -> TargetBackend.JVM JVM_IR_EXPECTATIONS_MARKER -> TargetBackend.JVM_IR + CLASSIC_FRONTEND_EXPECTATIONS_MARKER -> currentBackend + FIR_EXPECTATIONS_MARKER -> currentBackend + else -> error("Expected JVM backend: $line") + } + currentFrontend = when (line) { + EXPECTATIONS_MARKER -> frontend + JVM_EXPECTATIONS_MARKER -> currentFrontend + JVM_IR_EXPECTATIONS_MARKER -> currentFrontend + CLASSIC_FRONTEND_EXPECTATIONS_MARKER -> FrontendKinds.ClassicFrontend + FIR_EXPECTATIONS_MARKER -> FrontendKinds.FIR else -> error("Expected JVM backend: $line") } continue } - if (currentBackend == TargetBackend.ANY || currentBackend == backend) { + if ((currentBackend == TargetBackend.ANY || currentBackend == backend) && + currentFrontend == frontend) { if (actualLineNumbersIterator.hasNext()) { actual.add(actualLineNumbersIterator.next()) } diff --git a/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java b/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java index 09afbabd6ff..beaa84139e7 100644 --- a/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java +++ b/compiler/tests-gen/org/jetbrains/kotlin/ir/KlibTextTestCaseGenerated.java @@ -1831,6 +1831,11 @@ public class KlibTextTestCaseGenerated extends AbstractKlibTextTestCase { runTest("compiler/testData/ir/irText/lambdas/justLambda.kt"); } + @TestMetadata("lambdaReturningUnit.kt") + public void testLambdaReturningUnit() throws Exception { + runTest("compiler/testData/ir/irText/lambdas/lambdaReturningUnit.kt"); + } + @TestMetadata("localFunction.kt") public void testLocalFunction() throws Exception { runTest("compiler/testData/ir/irText/lambdas/localFunction.kt");