JVM IR: do not resolve fake override in InterfaceSuperCallsLowering

This leads to problems after 4dd794c2d2, because the immediate super
function's DefaultImpls and the implementation's DefaultImpls have
differing type parameters.

Looks like resolveFakeOverride was used here (maybe unintentionally) as
a workaround to the problem caused by the incorrect origin check in
isDefinitelyNotDefaultImplsMethod.
This commit is contained in:
Alexander Udalov
2020-02-06 16:46:49 +01:00
parent d9cbc459d0
commit 15ff74209c
8 changed files with 49 additions and 7 deletions
@@ -126,11 +126,8 @@ private class InterfaceSuperCallsLowering(val context: JvmBackendContext) : IrEl
return super.visitCall(expression)
}
// TODO: This is too eagerly resolving the fake override statically. It
// should cf the old backend call precisely <supertype>.foo, not
// resolve foo to its implementation.
val superCallee = (expression.symbol.owner as IrSimpleFunction).resolveFakeOverride()!!
if (superCallee.isDefinitelyNotDefaultImplsMethod() || superCallee.hasJvmDefault()) return super.visitCall(expression)
val superCallee = expression.symbol.owner as IrSimpleFunction
if (superCallee.isDefinitelyNotDefaultImplsMethod()) return super.visitCall(expression)
val redirectTarget = context.declarationFactory.getDefaultImplsFunction(superCallee)
val newCall = createDelegatingCallWithPlaceholderTypeArguments(expression, redirectTarget, context.irBuiltIns)
@@ -174,9 +171,10 @@ private class InterfaceDefaultCallsLowering(val context: JvmBackendContext) : Ir
}
private fun IrSimpleFunction.isDefinitelyNotDefaultImplsMethod() =
resolveFakeOverride()?.let { origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB } == true ||
resolveFakeOverride()?.origin == IrDeclarationOrigin.IR_EXTERNAL_JAVA_DECLARATION_STUB ||
origin == IrDeclarationOrigin.FUNCTION_FOR_DEFAULT_PARAMETER ||
hasAnnotation(PLATFORM_DEPENDENT_ANNOTATION_FQ_NAME) ||
hasJvmDefault() ||
(name.asString() == "clone" &&
parent.safeAs<IrClass>()?.fqNameWhenAvailable?.asString() == "kotlin.Cloneable" &&
valueParameters.isEmpty())
@@ -237,7 +235,6 @@ internal fun IrSimpleFunction.findInterfaceImplementation(): IrSimpleFunction? {
|| Visibilities.isPrivate(implementation.visibility)
|| implementation.isDefinitelyNotDefaultImplsMethod()
|| implementation.isMethodOfAny()
|| implementation.hasJvmDefault()
) {
return null
}
@@ -0,0 +1,15 @@
// IGNORE_BACKEND_FIR: JVM_IR
interface A {
fun foo(o: String): String = o + "K"
}
interface B<T> : A
class C : B<Int> {
override fun foo(o: String): String {
return super<B>.foo(o)
}
}
fun box(): String = C().foo("O")
@@ -27638,6 +27638,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/super/multipleSuperTraits.kt");
}
@TestMetadata("superCallToNonGenericImplThroughGenericDefaultImpls.kt")
public void testSuperCallToNonGenericImplThroughGenericDefaultImpls() throws Exception {
runTest("compiler/testData/codegen/box/super/superCallToNonGenericImplThroughGenericDefaultImpls.kt");
}
@TestMetadata("traitproperty.kt")
public void testTraitproperty() throws Exception {
runTest("compiler/testData/codegen/box/super/traitproperty.kt");
@@ -26455,6 +26455,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/super/multipleSuperTraits.kt");
}
@TestMetadata("superCallToNonGenericImplThroughGenericDefaultImpls.kt")
public void testSuperCallToNonGenericImplThroughGenericDefaultImpls() throws Exception {
runTest("compiler/testData/codegen/box/super/superCallToNonGenericImplThroughGenericDefaultImpls.kt");
}
@TestMetadata("traitproperty.kt")
public void testTraitproperty() throws Exception {
runTest("compiler/testData/codegen/box/super/traitproperty.kt");
@@ -26142,6 +26142,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
runTest("compiler/testData/codegen/box/super/multipleSuperTraits.kt");
}
@TestMetadata("superCallToNonGenericImplThroughGenericDefaultImpls.kt")
public void testSuperCallToNonGenericImplThroughGenericDefaultImpls() throws Exception {
runTest("compiler/testData/codegen/box/super/superCallToNonGenericImplThroughGenericDefaultImpls.kt");
}
@TestMetadata("traitproperty.kt")
public void testTraitproperty() throws Exception {
runTest("compiler/testData/codegen/box/super/traitproperty.kt");
@@ -26142,6 +26142,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/super/multipleSuperTraits.kt");
}
@TestMetadata("superCallToNonGenericImplThroughGenericDefaultImpls.kt")
public void testSuperCallToNonGenericImplThroughGenericDefaultImpls() throws Exception {
runTest("compiler/testData/codegen/box/super/superCallToNonGenericImplThroughGenericDefaultImpls.kt");
}
@TestMetadata("traitproperty.kt")
public void testTraitproperty() throws Exception {
runTest("compiler/testData/codegen/box/super/traitproperty.kt");
@@ -21288,6 +21288,11 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/super/multipleSuperTraits.kt");
}
@TestMetadata("superCallToNonGenericImplThroughGenericDefaultImpls.kt")
public void testSuperCallToNonGenericImplThroughGenericDefaultImpls() throws Exception {
runTest("compiler/testData/codegen/box/super/superCallToNonGenericImplThroughGenericDefaultImpls.kt");
}
@TestMetadata("traitproperty.kt")
public void testTraitproperty() throws Exception {
runTest("compiler/testData/codegen/box/super/traitproperty.kt");
@@ -21348,6 +21348,11 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
runTest("compiler/testData/codegen/box/super/multipleSuperTraits.kt");
}
@TestMetadata("superCallToNonGenericImplThroughGenericDefaultImpls.kt")
public void testSuperCallToNonGenericImplThroughGenericDefaultImpls() throws Exception {
runTest("compiler/testData/codegen/box/super/superCallToNonGenericImplThroughGenericDefaultImpls.kt");
}
@TestMetadata("traitproperty.kt")
public void testTraitproperty() throws Exception {
runTest("compiler/testData/codegen/box/super/traitproperty.kt");