K2: change API around collect/lookupSupertypes
In this commit we now require a class-like symbol (and not a more general classifier symbol) whenever possible. Exceptional situation with a type parameter is now handled in Synthetics.kt Related to KT-63569
This commit is contained in:
committed by
Space Team
parent
49e786f088
commit
8924e46458
@@ -64,7 +64,7 @@ fun collectSymbolsForType(type: ConeKotlinType, useSiteSession: FirSession): Lis
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun lookupSuperTypes(
|
fun lookupSuperTypes(
|
||||||
symbols: List<FirClassifierSymbol<*>>,
|
symbols: List<FirClassSymbol<*>>,
|
||||||
lookupInterfaces: Boolean,
|
lookupInterfaces: Boolean,
|
||||||
deep: Boolean,
|
deep: Boolean,
|
||||||
useSiteSession: FirSession,
|
useSiteSession: FirSession,
|
||||||
@@ -161,7 +161,7 @@ fun FirClass.isThereLoopInSupertypes(session: FirSession): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fun lookupSuperTypes(
|
fun lookupSuperTypes(
|
||||||
symbol: FirClassifierSymbol<*>,
|
symbol: FirClassLikeSymbol<*>,
|
||||||
lookupInterfaces: Boolean,
|
lookupInterfaces: Boolean,
|
||||||
deep: Boolean,
|
deep: Boolean,
|
||||||
useSiteSession: FirSession
|
useSiteSession: FirSession
|
||||||
@@ -231,7 +231,7 @@ private fun ConeClassLikeType.computePartialExpansion(
|
|||||||
supertypeSupplier: SupertypeSupplier
|
supertypeSupplier: SupertypeSupplier
|
||||||
): ConeClassLikeType = fullyExpandedType(useSiteSession) { supertypeSupplier.expansionForTypeAlias(it, useSiteSession) }
|
): ConeClassLikeType = fullyExpandedType(useSiteSession) { supertypeSupplier.expansionForTypeAlias(it, useSiteSession) }
|
||||||
|
|
||||||
private fun FirClassifierSymbol<*>.collectSuperTypes(
|
private fun FirClassLikeSymbol<*>.collectSuperTypes(
|
||||||
list: MutableList<ConeClassLikeType>,
|
list: MutableList<ConeClassLikeType>,
|
||||||
visitedSymbols: MutableSet<FirClassifierSymbol<*>>,
|
visitedSymbols: MutableSet<FirClassifierSymbol<*>>,
|
||||||
deep: Boolean,
|
deep: Boolean,
|
||||||
@@ -287,7 +287,6 @@ private fun FirClassifierSymbol<*>.collectSuperTypes(
|
|||||||
expansion.lookupTag.toSymbol(useSiteSession)
|
expansion.lookupTag.toSymbol(useSiteSession)
|
||||||
?.collectSuperTypes(list, visitedSymbols, deep, lookupInterfaces, substituteSuperTypes, useSiteSession, supertypeSupplier)
|
?.collectSuperTypes(list, visitedSymbols, deep, lookupInterfaces, substituteSuperTypes, useSiteSession, supertypeSupplier)
|
||||||
}
|
}
|
||||||
else -> error("?!id:1")
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,8 +15,10 @@ import org.jetbrains.kotlin.fir.resolve.toSymbol
|
|||||||
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
import org.jetbrains.kotlin.fir.resolve.transformers.ReturnTypeCalculator
|
||||||
import org.jetbrains.kotlin.fir.scopes.*
|
import org.jetbrains.kotlin.fir.scopes.*
|
||||||
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
import org.jetbrains.kotlin.fir.symbols.SyntheticSymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirClassLikeSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirSyntheticPropertySymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirSyntheticPropertySymbol
|
||||||
|
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||||
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
import org.jetbrains.kotlin.fir.symbols.impl.FirVariableSymbol
|
||||||
import org.jetbrains.kotlin.fir.types.*
|
import org.jetbrains.kotlin.fir.types.*
|
||||||
import org.jetbrains.kotlin.name.CallableId
|
import org.jetbrains.kotlin.name.CallableId
|
||||||
@@ -277,7 +279,7 @@ class FirSyntheticPropertiesScope private constructor(
|
|||||||
*/
|
*/
|
||||||
private fun isJavaTypeOnThePath(baseType: ConeSimpleKotlinType?): Boolean {
|
private fun isJavaTypeOnThePath(baseType: ConeSimpleKotlinType?): Boolean {
|
||||||
val lookupTagToStop = (baseType as? ConeLookupTagBasedType)?.lookupTag ?: return false
|
val lookupTagToStop = (baseType as? ConeLookupTagBasedType)?.lookupTag ?: return false
|
||||||
val dispatchReceiverClass = (dispatchReceiverType as? ConeLookupTagBasedType)?.lookupTag?.toSymbol(session) ?: return false
|
val dispatchReceiverClassSymbol = (dispatchReceiverType as? ConeLookupTagBasedType)?.lookupTag?.toSymbol(session) ?: return false
|
||||||
|
|
||||||
val typeContext = session.typeContext
|
val typeContext = session.typeContext
|
||||||
fun checkType(type: ConeClassLikeType): Boolean {
|
fun checkType(type: ConeClassLikeType): Boolean {
|
||||||
@@ -294,10 +296,17 @@ class FirSyntheticPropertiesScope private constructor(
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
val superTypes = lookupSuperTypes(dispatchReceiverClass, lookupInterfaces = true, deep = true, session)
|
when (dispatchReceiverClassSymbol) {
|
||||||
for (superType in superTypes) {
|
is FirClassLikeSymbol -> {
|
||||||
if (checkType(superType)) return true
|
val superTypes = lookupSuperTypes(dispatchReceiverClassSymbol, lookupInterfaces = true, deep = true, session)
|
||||||
|
for (superType in superTypes) {
|
||||||
|
if (checkType(superType)) return true
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
is FirTypeParameterSymbol -> {
|
||||||
|
error("Type parameter symbol ${dispatchReceiverClassSymbol.name} is not expected here")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user