Minor. FIR: Simplify createFunctionalType
^KT-32725 In Progress
This commit is contained in:
@@ -6,7 +6,8 @@
|
||||
package org.jetbrains.kotlin.fir.resolve
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.ClassKind
|
||||
import org.jetbrains.kotlin.fir.*
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.componentArrayAccessor
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.expressions.FirQualifiedAccess
|
||||
import org.jetbrains.kotlin.fir.expressions.FirResolvable
|
||||
@@ -14,9 +15,11 @@ import org.jetbrains.kotlin.fir.expressions.FirResolvedQualifier
|
||||
import org.jetbrains.kotlin.fir.references.FirErrorNamedReference
|
||||
import org.jetbrains.kotlin.fir.references.FirResolvedCallableReference
|
||||
import org.jetbrains.kotlin.fir.references.FirThisReference
|
||||
import org.jetbrains.kotlin.fir.render
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.AbstractConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.resultType
|
||||
import org.jetbrains.kotlin.fir.resolvedTypeFromPrototype
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.FirMemberScopeProvider
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.withReplacedConeType
|
||||
import org.jetbrains.kotlin.fir.symbols.*
|
||||
@@ -205,13 +208,12 @@ fun FirFunction<*>.constructFunctionalTypeRef(session: FirSession): FirResolvedT
|
||||
}
|
||||
val rawReturnType = (this as FirTypedDeclaration).returnTypeRef.coneTypeUnsafe<ConeKotlinType>()
|
||||
|
||||
val functionalType = createFunctionalType(session, parameters, receiverTypeRef?.coneTypeUnsafe(), rawReturnType)
|
||||
val functionalType = createFunctionalType(parameters, receiverTypeRef?.coneTypeUnsafe(), rawReturnType)
|
||||
|
||||
return FirResolvedTypeRefImpl(psi, functionalType)
|
||||
}
|
||||
|
||||
fun createFunctionalType(
|
||||
session: FirSession,
|
||||
parameters: List<ConeKotlinType>,
|
||||
receiverType: ConeKotlinType?,
|
||||
rawReturnType: ConeKotlinType
|
||||
@@ -219,15 +221,14 @@ fun createFunctionalType(
|
||||
val receiverAndParameterTypes = listOfNotNull(receiverType) + parameters + listOf(rawReturnType)
|
||||
|
||||
val functionalTypeId = StandardClassIds.byName("Function${receiverAndParameterTypes.size - 1}")
|
||||
val functionalType = functionalTypeId(session.firSymbolProvider).constructType(receiverAndParameterTypes.toTypedArray(), isNullable = false)
|
||||
return functionalType
|
||||
return ConeClassTypeImpl(ConeClassLikeLookupTagImpl(functionalTypeId), receiverAndParameterTypes.toTypedArray(), isNullable = false)
|
||||
}
|
||||
|
||||
fun BodyResolveComponents.typeForQualifier(resolvedQualifier: FirResolvedQualifier): FirTypeRef {
|
||||
val classId = resolvedQualifier.classId
|
||||
val resultType = resolvedQualifier.resultType
|
||||
if (classId != null) {
|
||||
val classSymbol: FirClassLikeSymbol<*> = symbolProvider.getClassLikeSymbolByFqName(classId)!!
|
||||
val classSymbol = symbolProvider.getClassLikeSymbolByFqName(classId)!!
|
||||
val declaration = classSymbol.phasedFir
|
||||
if (declaration is FirClass) {
|
||||
if (declaration.classKind == ClassKind.OBJECT) {
|
||||
@@ -311,8 +312,10 @@ private fun BodyResolveComponents.typeFromSymbol(symbol: AbstractFirBasedSymbol<
|
||||
"no enum item supertype"
|
||||
)
|
||||
} else
|
||||
FirResolvedTypeRefImpl(null, symbol.constructType(emptyArray(), isNullable = false))
|
||||
FirResolvedTypeRefImpl(
|
||||
null, symbol.constructType(emptyArray(), isNullable = false)
|
||||
)
|
||||
}
|
||||
else -> error("WTF ! $symbol")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -191,7 +191,7 @@ class FirSamResolverImpl(
|
||||
val abstractMethod = firRegularClass.getSingleAbstractMethodOrNull(firSession, scopeSession) ?: return@getOrPut NULL_STUB
|
||||
// TODO: val shouldConvertFirstParameterToDescriptor = samWithReceiverResolvers.any { it.shouldConvertFirstSamParameterToReceiver(abstractMethod) }
|
||||
|
||||
abstractMethod.getFunctionTypeForAbstractMethod(firSession)
|
||||
abstractMethod.getFunctionTypeForAbstractMethod()
|
||||
} as? ConeKotlinType
|
||||
}
|
||||
|
||||
@@ -292,14 +292,13 @@ private fun FirRegularClass.hasMoreThenOneAbstractFunctionOrHasAbstractProperty(
|
||||
return false
|
||||
}
|
||||
|
||||
private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(session: FirSession): ConeLookupTagBasedType {
|
||||
private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(): ConeLookupTagBasedType {
|
||||
val parameterTypes = valueParameters.map {
|
||||
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType("No type for parameter $it")
|
||||
}
|
||||
|
||||
return createFunctionalType(
|
||||
session, parameterTypes,
|
||||
receiverType = null,
|
||||
parameterTypes, receiverType = null,
|
||||
rawReturnType = returnTypeRef.coneTypeSafe() ?: ConeKotlinErrorType("No type for return type of $this")
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user