FIR: Weaken requirements for all symbols to have correct FIR
Currently, some cases like library type parameters are not supported properly
This commit is contained in:
@@ -10,7 +10,6 @@ import org.jetbrains.kotlin.fir.declarations.expandedConeType
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.symbols.*
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeAbbreviatedTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl
|
||||
@@ -42,11 +41,10 @@ fun ConeAbbreviatedType.directExpansionType(useSiteSession: FirSession): ConeCla
|
||||
fun ConeClassifierLookupTag.toSymbol(useSiteSession: FirSession): ConeClassifierSymbol? =
|
||||
when (this) {
|
||||
is ConeClassLikeLookupTag -> toSymbol(useSiteSession)
|
||||
is FirTypeParameterSymbol -> this.symbol
|
||||
is ConeTypeParameterSymbol -> this
|
||||
else -> error("sealed")
|
||||
}
|
||||
|
||||
|
||||
fun ConeClassifierSymbol.constructType(typeArguments: Array<ConeKotlinTypeProjection>, isNullable: Boolean): ConeLookupTagBasedType {
|
||||
return when (this) {
|
||||
is ConeTypeParameterSymbol -> {
|
||||
@@ -127,4 +125,4 @@ fun <T : ConeKotlinType> T.withArguments(arguments: Array<ConeKotlinTypeProjecti
|
||||
//is ConeFunctionTypeImpl -> ConeFunctionTypeImpl(receiverType, parameterTypes, returnType, lookupTag, nullability.isNullable) as T
|
||||
else -> error("Not supported: $this: ${this.render()}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,9 +8,11 @@ package org.jetbrains.kotlin.fir.resolve
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirRegularClass
|
||||
import org.jetbrains.kotlin.fir.declarations.FirTypeParameter
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.firSafeNullable
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.firUnsafe
|
||||
import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirCompositeScope
|
||||
import org.jetbrains.kotlin.fir.symbols.FirBasedSymbol
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeClassTypeImpl
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
@@ -21,11 +23,15 @@ fun ConeKotlinType.scope(useSiteSession: FirSession): FirScope? {
|
||||
is ConeClassErrorType -> null
|
||||
is ConeAbbreviatedType -> directExpansionType(useSiteSession)?.scope(useSiteSession)
|
||||
is ConeClassLikeType -> {
|
||||
val fir = this.lookupTag.toSymbol(useSiteSession)?.firUnsafe<FirRegularClass>() ?: return null
|
||||
// For ConeClassLikeType they might be a type alias instead of a regular class
|
||||
// TODO: support that case and switch back to `firUnsafe` instead of `firSafeNullable`
|
||||
val fir = this.lookupTag.toSymbol(useSiteSession)?.firSafeNullable<FirRegularClass>() ?: return null
|
||||
fir.buildUseSiteScope(useSiteSession)
|
||||
}
|
||||
is ConeTypeParameterType -> {
|
||||
val fir = this.lookupTag.toSymbol(useSiteSession)?.firUnsafe<FirTypeParameter>() ?: return null
|
||||
// TODO: support LibraryTypeParameterSymbol or get rid of it
|
||||
val toSymbol = this.lookupTag.toSymbol(useSiteSession)?.takeIf { it is FirBasedSymbol<*> } ?: return null
|
||||
val fir = toSymbol.firUnsafe<FirTypeParameter>()
|
||||
FirCompositeScope(fir.bounds.mapNotNullTo(mutableListOf()) { it.coneTypeUnsafe().scope(useSiteSession) })
|
||||
}
|
||||
is ConeFlexibleType -> lowerBound.scope(useSiteSession)
|
||||
@@ -47,4 +53,4 @@ fun FirRegularClass.defaultType(): ConeClassTypeImpl {
|
||||
}.toTypedArray(),
|
||||
isNullable = false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -544,6 +544,11 @@ inline fun <reified T : FirElement> ConeSymbol.firUnsafe(): T {
|
||||
return fir
|
||||
}
|
||||
|
||||
inline fun <reified T : FirElement> ConeSymbol.firSafeNullable(): T? {
|
||||
if (this !is FirBasedSymbol<*>) return null
|
||||
return fir as? T
|
||||
}
|
||||
|
||||
|
||||
interface ReturnTypeCalculator {
|
||||
fun tryCalculateReturnType(declaration: FirTypedDeclaration): FirResolvedTypeRef
|
||||
|
||||
Reference in New Issue
Block a user