Do not add continuation parameter for super interface bridges

If there is superinterface (more specifically, fun interface) in one
file with default suspend function, we lower the function, adding
continuation parameter. Then, when we compile another file with a child,
we generate a bridge to the default suspend function, which is already
lowered. So, we do not need to add the continuation parameter.

If the child is in the same file, then we add continuation parameter
after we create a bridge, so, AddContinuationLowering can encounter
bridges to suspend default functions in superinterfaces with
continuation parameter only in multifile examples.

 #KT-47549 Fixed
This commit is contained in:
Ilmir Usmanov
2021-12-02 00:43:40 +01:00
committed by Space
parent be6409f0af
commit b26a81435f
12 changed files with 253 additions and 47 deletions
@@ -385,8 +385,13 @@ private class AddContinuationLowering(context: JvmBackendContext) : SuspendLower
// the result is called 'view', just to be consistent with old backend.
private fun IrSimpleFunction.suspendFunctionViewOrStub(context: JvmBackendContext): IrSimpleFunction {
if (!isSuspend) return this
// If superinterface is in another file, the bridge to default method will already have continuation parameter,
// so skip it. See KT-47549.
if (origin == JvmLoweredDeclarationOrigin.SUPER_INTERFACE_METHOD_BRIDGE &&
valueParameters.lastOrNull()?.origin == JvmLoweredDeclarationOrigin.CONTINUATION_CLASS
) return this
// We need to use suspend function originals here, since if we use 'this' here,
// turing FlowCollector into 'fun interface' leads to AbstractMethodError
// turing FlowCollector into 'fun interface' leads to AbstractMethodError. See KT-49294.
return context.suspendFunctionOriginalToView.getOrPut(suspendFunctionOriginal()) { createSuspendFunctionStub(context) }
}