FIR: fix scope order for super-type resolve #KT-48159 Fixed

This commit is contained in:
Mikhail Glukhikh
2021-08-10 11:39:28 +03:00
parent ca98417a0c
commit b617aca8ee
3 changed files with 13 additions and 11 deletions
@@ -6,7 +6,7 @@ FILE: UastPatterns.kt
public abstract interface UReferenceExpression : R|UExpression| { public abstract interface UReferenceExpression : R|UExpression| {
} }
public final fun injectionHostOrReferenceExpression(): R|UExpressionPattern.Capture<UExpression>| { public final fun injectionHostOrReferenceExpression(): R|UExpressionPattern.Capture<UExpression>| {
^injectionHostOrReferenceExpression R|/uExpression|().<CS errors: /UExpressionPattern.Capture.filter>#(<L> = filter@fun <anonymous>(it: R|UExpression|): R|kotlin/Boolean| <inline=NoInline> { ^injectionHostOrReferenceExpression R|/uExpression|().R|SubstitutionOverride</UExpressionPattern.Capture.filter: R|UExpressionPattern.Capture<UExpression>|>|(<L> = filter@fun <anonymous>(it: R|UExpression|): R|kotlin/Boolean| <inline=NoInline> {
^ (R|<local>/it| is R|UReferenceExpression|) ^ (R|<local>/it| is R|UReferenceExpression|)
} }
) )
@@ -32,9 +32,9 @@ FILE: UastPatterns.kt
super<R|UElementPattern<T, Self>|>(R|<local>/clazz|) super<R|UElementPattern<T, Self>|>(R|<local>/clazz|)
} }
public open class Capture<T : R|UExpression|> : R|UExpressionPattern<T, ObjectPattern.Capture<T>>| { public open class Capture<T : R|UExpression|> : R|UExpressionPattern<T, UExpressionPattern.Capture<T>>| {
public constructor<T : R|UExpression|>(clazz: R|java/lang/Class<T>|): R|UExpressionPattern.Capture<T>| { public constructor<T : R|UExpression|>(clazz: R|java/lang/Class<T>|): R|UExpressionPattern.Capture<T>| {
super<R|UExpressionPattern<T, ObjectPattern.Capture<T>>|>(R|<local>/clazz|) super<R|UExpressionPattern<T, UExpressionPattern.Capture<T>>|>(R|<local>/clazz|)
} }
} }
@@ -23,7 +23,7 @@ interface UExpression : UElement
interface UReferenceExpression : UExpression interface UReferenceExpression : UExpression
fun injectionHostOrReferenceExpression(): UExpressionPattern.Capture<UExpression> = fun injectionHostOrReferenceExpression(): UExpressionPattern.Capture<UExpression> =
<!RETURN_TYPE_MISMATCH, TYPE_MISMATCH!>uExpression().filter { it is UReferenceExpression }<!> uExpression().filter { it is UReferenceExpression }
fun uExpression(): UExpressionPattern.Capture<UExpression> = expressionCapture(UExpression::class.java) fun uExpression(): UExpressionPattern.Capture<UExpression> = expressionCapture(UExpression::class.java)
@@ -34,5 +34,5 @@ open class UElementPattern<T : UElement, Self : UElementPattern<T, Self>>(clazz:
} }
open class UExpressionPattern<T : UExpression, Self : UExpressionPattern<T, Self>>(clazz: Class<T>) : UElementPattern<T, Self>(clazz) { open class UExpressionPattern<T : UExpression, Self : UExpressionPattern<T, Self>>(clazz: Class<T>) : UElementPattern<T, Self>(clazz) {
open class Capture<T : UExpression>(clazz: Class<T>) : UExpressionPattern<T, <!UPPER_BOUND_VIOLATED!>Capture<T><!>>(<!ARGUMENT_TYPE_MISMATCH!>clazz<!>) open class Capture<T : UExpression>(clazz: Class<T>) : UExpressionPattern<T, Capture<T>>(clazz)
} }
@@ -170,6 +170,14 @@ private fun createScopesForNestedClasses(
supertypeComputationSession: SupertypeComputationSession supertypeComputationSession: SupertypeComputationSession
): Collection<FirScope> = ): Collection<FirScope> =
mutableListOf<FirScope>().apply { mutableListOf<FirScope>().apply {
// Note: from higher priority to lower priority
// See also: BodyResolveContext.withScopesForClass
addIfNotNull(klass.typeParametersScope())
addIfNotNull(session.nestedClassifierScope(klass))
val companionObjects = klass.declarations.filterIsInstance<FirRegularClass>().filter { it.isCompanion }
for (companionObject in companionObjects) {
addIfNotNull(session.nestedClassifierScope(companionObject))
}
lookupSuperTypes( lookupSuperTypes(
klass, klass,
lookupInterfaces = false, deep = true, substituteTypes = true, useSiteSession = session, lookupInterfaces = false, deep = true, substituteTypes = true, useSiteSession = session,
@@ -178,12 +186,6 @@ private fun createScopesForNestedClasses(
it.lookupTag.getNestedClassifierScope(session, scopeSession) it.lookupTag.getNestedClassifierScope(session, scopeSession)
?.wrapNestedClassifierScopeWithSubstitutionForSuperType(it, session) ?.wrapNestedClassifierScopeWithSubstitutionForSuperType(it, session)
} }
addIfNotNull(klass.typeParametersScope())
val companionObjects = klass.declarations.filterIsInstance<FirRegularClass>().filter { it.isCompanion }
for (companionObject in companionObjects) {
addIfNotNull(session.nestedClassifierScope(companionObject))
}
addIfNotNull(session.nestedClassifierScope(klass))
} }
fun FirRegularClass.resolveSupertypesInTheAir(session: FirSession): List<FirTypeRef> { fun FirRegularClass.resolveSupertypesInTheAir(session: FirSession): List<FirTypeRef> {