From f3b5ee4cba046edd286b3fe6ae0274e2fb8fb5f4 Mon Sep 17 00:00:00 2001 From: Mikhail Glukhikh Date: Fri, 27 Dec 2019 11:37:28 +0300 Subject: [PATCH] FIR2IR: fix assertion in getIrFunctionSymbol (anonymous function case) --- .../fir/backend/Fir2IrDeclarationStorage.kt | 16 +++++++++++++--- .../ir/irText/lambdas/extensionLambda.fir.txt | 2 +- .../lambdas/multipleImplicitReceivers.fir.txt | 2 +- .../testData/ir/irText/stubs/builtinMap.fir.txt | 2 +- 4 files changed, 16 insertions(+), 6 deletions(-) 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 4824ad70be9..bb64d26cb19 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 @@ -407,7 +407,11 @@ class Fir2IrDeclarationStorage( return created } - fun getIrLocalFunction(function: FirAnonymousFunction): IrSimpleFunction { + fun getIrLocalFunction( + function: FirAnonymousFunction, + irParent: IrDeclarationParent? = null, + shouldLeaveScope: Boolean = false + ): IrSimpleFunction { val descriptor = WrappedSimpleFunctionDescriptor() val isLambda = function.psi is KtFunctionLiteral val origin = if (isLambda) IrDeclarationOrigin.LOCAL_FUNCTION_FOR_LAMBDA else IrDeclarationOrigin.DEFINED @@ -426,7 +430,7 @@ class Fir2IrDeclarationStorage( isOperator = false ) }.bindAndDeclareParameters( - function, descriptor, irParent = null, isStatic = false, shouldLeaveScope = false + function, descriptor, irParent = irParent, isStatic = false, shouldLeaveScope = shouldLeaveScope ) } } @@ -674,13 +678,19 @@ class Fir2IrDeclarationStorage( } irSymbolTable.referenceSimpleFunction(irDeclaration.descriptor) } + is FirAnonymousFunction -> { + val irDeclaration = getIrLocalFunction(firDeclaration, irParent, shouldLeaveScope = true).apply { + setAndModifyParent(irParent) + } + irSymbolTable.referenceSimpleFunction(irDeclaration.descriptor) + } is FirConstructor -> { val irDeclaration = getIrConstructor(firDeclaration, irParent, shouldLeaveScope = true).apply { setAndModifyParent(irParent) } irSymbolTable.referenceConstructor(irDeclaration.descriptor) } - else -> throw AssertionError("Should not be here") + else -> throw AssertionError("Should not be here: ${firDeclaration::class.java}: ${firDeclaration.render()}") } } diff --git a/compiler/testData/ir/irText/lambdas/extensionLambda.fir.txt b/compiler/testData/ir/irText/lambdas/extensionLambda.fir.txt index 40e8c507b5d..a4683ba6272 100644 --- a/compiler/testData/ir/irText/lambdas/extensionLambda.fir.txt +++ b/compiler/testData/ir/irText/lambdas/extensionLambda.fir.txt @@ -10,4 +10,4 @@ FILE fqName: fileName:/extensionLambda.kt FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Int BLOCK_BODY CALL 'public open fun (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=null - $this: GET_VAR ': kotlin.String declared in kotlin.String' type=kotlin.String origin=null + $this: ERROR_CALL 'Unresolved reference: this@R|special/anonymous|' type=kotlin.String diff --git a/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.txt b/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.txt index 26e735ddafe..e88adefba39 100644 --- a/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.txt +++ b/compiler/testData/ir/irText/lambdas/multipleImplicitReceivers.fir.txt @@ -106,4 +106,4 @@ FILE fqName: fileName:/multipleImplicitReceivers.kt FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Int BLOCK_BODY CALL 'public open fun invoke (): kotlin.Int [operator] declared in .IInvoke' type=kotlin.Int origin=null - $this: GET_VAR ': .IInvoke declared in .IInvoke' type=.IInvoke origin=null + $this: ERROR_CALL 'Unresolved reference: this@R|special/anonymous|' type=.IInvoke diff --git a/compiler/testData/ir/irText/stubs/builtinMap.fir.txt b/compiler/testData/ir/irText/stubs/builtinMap.fir.txt index e30cda442e5..bfbf582f470 100644 --- a/compiler/testData/ir/irText/stubs/builtinMap.fir.txt +++ b/compiler/testData/ir/irText/stubs/builtinMap.fir.txt @@ -26,7 +26,7 @@ FILE fqName: fileName:/builtinMap.kt FUN LOCAL_FUNCTION_FOR_LAMBDA name: visibility:local modality:FINAL <> () returnType:kotlin.Unit BLOCK_BODY CALL 'public open fun put (p0: K1 of .plus, p1: V1 of .plus): V1 of .plus? [operator] declared in java.util.HashMap' type=V1 of .plus? origin=null - $this: GET_VAR ': java.util.HashMap declared in java.util.HashMap' type=java.util.HashMap<*, *> origin=null + $this: ERROR_CALL 'Unresolved reference: this@R|special/anonymous|' type=java.util.LinkedHashMap.plus, V1 of .plus> p0: CALL 'public final fun (): K1 of .plus declared in kotlin.Pair' type=K1 of .plus origin=null $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 (): V1 of .plus declared in kotlin.Pair' type=V1 of .plus origin=null