FE: add & fix test with intersection property shadowed by base field

This commit is contained in:
Mikhail Glukhikh
2022-12-20 15:03:34 +01:00
committed by teamcity
parent 949a39b80f
commit 7904f23660
13 changed files with 177 additions and 16 deletions
@@ -21,6 +21,6 @@ FILE: lib.kt
}
FILE: main.kt
public final fun test(d: R|D|): R|kotlin/Unit| {
lval a: R|kotlin/Int| = R|<local>/d|.R|/C.x|
lval a: R|kotlin/Int| = R|<local>/d|.R|/A.x|
lval b: R|kotlin/Int| = R|<local>/d|.R|/D.y|
}
@@ -225,6 +225,12 @@ public class FirOldFrontendDiagnosticsTestGenerated extends AbstractFirDiagnosti
runTest("compiler/testData/diagnostics/tests/derivedClassPropertyShadowsBaseClassField13.kt");
}
@Test
@TestMetadata("derivedIntersectionPropertyShadowsBaseClassField.kt")
public void testDerivedIntersectionPropertyShadowsBaseClassField() throws Exception {
runTest("compiler/testData/diagnostics/tests/derivedIntersectionPropertyShadowsBaseClassField.kt");
}
@Test
@TestMetadata("DiamondFunction.kt")
public void testDiamondFunction() throws Exception {
@@ -225,6 +225,12 @@ public class FirOldFrontendDiagnosticsWithLightTreeTestGenerated extends Abstrac
runTest("compiler/testData/diagnostics/tests/derivedClassPropertyShadowsBaseClassField13.kt");
}
@Test
@TestMetadata("derivedIntersectionPropertyShadowsBaseClassField.kt")
public void testDerivedIntersectionPropertyShadowsBaseClassField() throws Exception {
runTest("compiler/testData/diagnostics/tests/derivedIntersectionPropertyShadowsBaseClassField.kt");
}
@Test
@TestMetadata("DiamondFunction.kt")
public void testDiamondFunction() throws Exception {
@@ -16,6 +16,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.Candidate
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
import org.jetbrains.kotlin.fir.unwrapFakeOverrides
import org.jetbrains.kotlin.fir.unwrapSubstitutionOverrides
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
class JvmPlatformOverloadsConflictResolver(
@@ -47,7 +48,7 @@ class JvmPlatformOverloadsConflictResolver(
}
private fun FirProperty.isShadowedByFieldCandidate(candidates: Set<Candidate>): Boolean {
val propertyContainingClassLookupTag = unwrapFakeOverrides().symbol.containingClassLookupTag() ?: return false
val propertyContainingClassLookupTag = unwrapSubstitutionOverrides().symbol.containingClassLookupTag() ?: return false
for (otherCandidate in candidates) {
val field = otherCandidate.symbol.fir as? FirField ?: continue
val fieldContainingClassLookupTag = field.unwrapFakeOverrides().symbol.containingClassLookupTag()
@@ -67,7 +68,7 @@ class JvmPlatformOverloadsConflictResolver(
val fieldContainingClassLookupTag = unwrapFakeOverrides().symbol.containingClassLookupTag() ?: return false
for (otherCandidate in candidates) {
val property = otherCandidate.symbol.fir as? FirProperty ?: continue
val propertyContainingClassLookupTag = property.unwrapFakeOverrides().symbol.containingClassLookupTag()
val propertyContainingClassLookupTag = property.unwrapSubstitutionOverrides().symbol.containingClassLookupTag()
if (propertyContainingClassLookupTag != null &&
propertyContainingClassLookupTag.strictlyDerivedFrom(fieldContainingClassLookupTag)
) {
@@ -93,6 +93,15 @@ inline fun <reified D : FirCallableDeclaration> D.unwrapFakeOverrides(): D {
} while (true)
}
inline fun <reified D : FirCallableDeclaration> D.unwrapSubstitutionOverrides(): D {
var current = this
do {
val next = current.originalForSubstitutionOverride ?: return current
current = next
} while (true)
}
inline fun <reified S : FirCallableSymbol<*>> S.unwrapFakeOverrides(): S = fir.unwrapFakeOverrides().symbol as S
private object SubstitutedOverrideOriginalKey : FirDeclarationDataKey()