FIR2IR: fix assertion in getIrFunctionSymbol (anonymous function case)

This commit is contained in:
Mikhail Glukhikh
2019-12-27 11:37:28 +03:00
parent 5e426fdc71
commit f3b5ee4cba
4 changed files with 16 additions and 6 deletions
@@ -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()}")
}
}
@@ -10,4 +10,4 @@ FILE fqName:<root> fileName:/extensionLambda.kt
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Int
BLOCK_BODY
CALL 'public open fun <get-length> (): kotlin.Int declared in kotlin.String' type=kotlin.Int origin=null
$this: GET_VAR '<this>: kotlin.String declared in kotlin.String' type=kotlin.String origin=null
$this: ERROR_CALL 'Unresolved reference: this@R|special/anonymous|' type=kotlin.String
@@ -106,4 +106,4 @@ FILE fqName:<root> fileName:/multipleImplicitReceivers.kt
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Int
BLOCK_BODY
CALL 'public open fun invoke (): kotlin.Int [operator] declared in <root>.IInvoke' type=kotlin.Int origin=null
$this: GET_VAR '<this>: <root>.IInvoke declared in <root>.IInvoke' type=<root>.IInvoke origin=null
$this: ERROR_CALL 'Unresolved reference: this@R|special/anonymous|' type=<root>.IInvoke
+1 -1
View File
@@ -26,7 +26,7 @@ FILE fqName:<root> fileName:/builtinMap.kt
FUN LOCAL_FUNCTION_FOR_LAMBDA name:<anonymous> visibility:local modality:FINAL <> () returnType:kotlin.Unit
BLOCK_BODY
CALL 'public open fun put (p0: K1 of <root>.plus, p1: V1 of <root>.plus): V1 of <root>.plus? [operator] declared in java.util.HashMap' type=V1 of <root>.plus? origin=null
$this: GET_VAR '<this>: 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<K1 of <root>.plus, V1 of <root>.plus>
p0: CALL 'public final fun <get-first> (): K1 of <root>.plus declared in kotlin.Pair' type=K1 of <root>.plus origin=null
$this: GET_VAR 'pair: kotlin.Pair<K1 of <root>.plus, V1 of <root>.plus> declared in <root>.plus' type=kotlin.Pair<K1 of <root>.plus, V1 of <root>.plus> origin=null
p1: CALL 'public final fun <get-second> (): V1 of <root>.plus declared in kotlin.Pair' type=V1 of <root>.plus origin=null