FIR2IR: Fix incorrect fake override structure for delegated member in supertype

In C, fake override for `name` should have B::name as base symbol, not Named::name
This commit is contained in:
Denis.Zharkov
2021-01-25 15:55:22 +03:00
parent 844d2572e5
commit d9f45fdf9e
7 changed files with 51 additions and 1 deletions
@@ -192,8 +192,10 @@ class FakeOverrideGenerator(
): List<S> {
if (symbol.fir.origin != FirDeclarationOrigin.IntersectionOverride) return listOf(basedSymbol)
return scope.directOverridden(symbol).map {
// Unwrapping should happen only for fake overrides members from the same class, not from supertypes
if (it.dispatchReceiverClassOrNull() != containingClass) return@map it
when {
it.fir.isSubstitutionOverride && it.dispatchReceiverClassOrNull() == containingClass ->
it.fir.isSubstitutionOverride ->
it.originalForSubstitutionOverride!!
it.fir.origin == FirDeclarationOrigin.Delegated ->
it.fir.delegatedWrapperData?.wrapped?.symbol!! as S
@@ -375,6 +375,11 @@ public class FirCompileKotlinAgainstKotlinTestGenerated extends AbstractFirCompi
runTest("compiler/testData/compileKotlinAgainstKotlin/nestedTypeAliasExpansion.kt");
}
@TestMetadata("noExplicitOverrideForDelegatedFromSupertype.kt")
public void testNoExplicitOverrideForDelegatedFromSupertype() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/noExplicitOverrideForDelegatedFromSupertype.kt");
}
@TestMetadata("optionalAnnotation.kt")
public void testOptionalAnnotation() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/optionalAnnotation.kt");
@@ -0,0 +1,23 @@
// TARGET_BACKEND: JVM
// FILE: A.kt
package a
interface Named {
val name: String
}
interface A : Named
// FILE: B.kt
import a.*
open class B(val a: A) : A by a, Named
class C(a: A) : B(a)
fun box(): String {
return C(object : A {
override val name: String
get() = "OK"
}).name
}
@@ -374,6 +374,11 @@ public class CompileKotlinAgainstKotlinTestGenerated extends AbstractCompileKotl
runTest("compiler/testData/compileKotlinAgainstKotlin/nestedTypeAliasExpansion.kt");
}
@TestMetadata("noExplicitOverrideForDelegatedFromSupertype.kt")
public void testNoExplicitOverrideForDelegatedFromSupertype() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/noExplicitOverrideForDelegatedFromSupertype.kt");
}
@TestMetadata("optionalAnnotation.kt")
public void testOptionalAnnotation() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/optionalAnnotation.kt");
@@ -375,6 +375,11 @@ public class IrCompileKotlinAgainstKotlinTestGenerated extends AbstractIrCompile
runTest("compiler/testData/compileKotlinAgainstKotlin/nestedTypeAliasExpansion.kt");
}
@TestMetadata("noExplicitOverrideForDelegatedFromSupertype.kt")
public void testNoExplicitOverrideForDelegatedFromSupertype() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/noExplicitOverrideForDelegatedFromSupertype.kt");
}
@TestMetadata("optionalAnnotation.kt")
public void testOptionalAnnotation() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/optionalAnnotation.kt");
@@ -375,6 +375,11 @@ public class JvmIrAgainstOldBoxTestGenerated extends AbstractJvmIrAgainstOldBoxT
runTest("compiler/testData/compileKotlinAgainstKotlin/nestedTypeAliasExpansion.kt");
}
@TestMetadata("noExplicitOverrideForDelegatedFromSupertype.kt")
public void testNoExplicitOverrideForDelegatedFromSupertype() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/noExplicitOverrideForDelegatedFromSupertype.kt");
}
@TestMetadata("optionalAnnotation.kt")
public void testOptionalAnnotation() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/optionalAnnotation.kt");
@@ -375,6 +375,11 @@ public class JvmOldAgainstIrBoxTestGenerated extends AbstractJvmOldAgainstIrBoxT
runTest("compiler/testData/compileKotlinAgainstKotlin/nestedTypeAliasExpansion.kt");
}
@TestMetadata("noExplicitOverrideForDelegatedFromSupertype.kt")
public void testNoExplicitOverrideForDelegatedFromSupertype() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/noExplicitOverrideForDelegatedFromSupertype.kt");
}
@TestMetadata("optionalAnnotation.kt")
public void testOptionalAnnotation() throws Exception {
runTest("compiler/testData/compileKotlinAgainstKotlin/optionalAnnotation.kt");