[FIR] Introduce & use FirTypeRef.coneType
This commit is contained in:
+1
-1
@@ -128,7 +128,7 @@ object FirAnnotationClassDeclarationChecker : FirBasicDeclarationChecker() {
|
||||
}
|
||||
|
||||
private fun isAllowedArray(typeRef: FirTypeRef, session: FirSession): Boolean {
|
||||
val typeArguments = typeRef.coneTypeUnsafe<ConeKotlinType>().typeArguments
|
||||
val typeArguments = typeRef.coneType.typeArguments
|
||||
|
||||
if (typeArguments.size != 1) return false
|
||||
|
||||
|
||||
+7
-10
@@ -17,13 +17,10 @@ import org.jetbrains.kotlin.fir.analysis.diagnostics.DiagnosticReporter
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirDiagnosticFactory3
|
||||
import org.jetbrains.kotlin.fir.analysis.diagnostics.FirErrors
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.resolve.firSymbolProvider
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.lexer.KtTokens
|
||||
|
||||
// TODO: check why coneTypeSafe is necessary at some points inside
|
||||
object FirExposedVisibilityChecker : FirMemberDeclarationChecker() {
|
||||
override fun check(declaration: FirMemberDeclaration, context: CheckerContext, reporter: DiagnosticReporter) {
|
||||
when (declaration) {
|
||||
@@ -67,7 +64,7 @@ object FirExposedVisibilityChecker : FirMemberDeclarationChecker() {
|
||||
val classVisibility = declaration.firEffectiveVisibility(declaration.session)
|
||||
for (parameter in declaration.typeParameters) {
|
||||
for (bound in parameter.symbol.fir.bounds) {
|
||||
val restricting = bound.coneTypeSafe<ConeKotlinType>()?.leastPermissiveDescriptor(declaration.session, classVisibility)
|
||||
val restricting = bound.coneType.leastPermissiveDescriptor(declaration.session, classVisibility)
|
||||
if (restricting != null) {
|
||||
reporter.reportExposure(
|
||||
FirErrors.EXPOSED_TYPE_PARAMETER_BOUND,
|
||||
@@ -99,8 +96,8 @@ object FirExposedVisibilityChecker : FirMemberDeclarationChecker() {
|
||||
private fun checkFunction(declaration: FirFunction<*>, reporter: DiagnosticReporter) {
|
||||
val functionVisibility = (declaration as FirMemberDeclaration).firEffectiveVisibility(declaration.session)
|
||||
if (declaration !is FirConstructor) {
|
||||
val restricting = declaration.returnTypeRef.coneTypeSafe<ConeKotlinType>()
|
||||
?.leastPermissiveDescriptor(declaration.session, functionVisibility)
|
||||
val restricting = declaration.returnTypeRef.coneType
|
||||
.leastPermissiveDescriptor(declaration.session, functionVisibility)
|
||||
if (restricting != null) {
|
||||
reporter.reportExposure(
|
||||
FirErrors.EXPOSED_FUNCTION_RETURN_TYPE,
|
||||
@@ -151,9 +148,9 @@ object FirExposedVisibilityChecker : FirMemberDeclarationChecker() {
|
||||
memberDeclaration: FirCallableMemberDeclaration<*>?, reporter: DiagnosticReporter
|
||||
) {
|
||||
if (typeRef == null || memberDeclaration == null) return
|
||||
val receiverParameterType = typeRef.coneTypeSafe<ConeKotlinType>()
|
||||
val receiverParameterType = typeRef.coneType
|
||||
val memberVisibility = memberDeclaration.firEffectiveVisibility(memberDeclaration.session)
|
||||
val restricting = receiverParameterType?.leastPermissiveDescriptor(memberDeclaration.session, memberVisibility)
|
||||
val restricting = receiverParameterType.leastPermissiveDescriptor(memberDeclaration.session, memberVisibility)
|
||||
if (restricting != null) {
|
||||
reporter.reportExposure(
|
||||
FirErrors.EXPOSED_RECEIVER_TYPE,
|
||||
|
||||
+2
-2
@@ -15,12 +15,12 @@ import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.ConeClassLikeLookupTag
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirCallableSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
private fun FirAnnotationCall.toAnnotationLookupTag(): ConeClassLikeLookupTag =
|
||||
((annotationTypeRef as FirResolvedTypeRef).type as ConeClassLikeType).lookupTag
|
||||
(annotationTypeRef.coneType as ConeClassLikeType).lookupTag
|
||||
|
||||
internal fun FirAnnotationCall.toAnnotationClassId(): ClassId =
|
||||
toAnnotationLookupTag().classId
|
||||
|
||||
+6
-8
@@ -488,13 +488,11 @@ class FirElementSerializer private constructor(
|
||||
}
|
||||
|
||||
if (parameter.isVararg) {
|
||||
val varargElementType = parameter.returnTypeRef.coneTypeSafe<ConeKotlinType>()?.varargElementType(session)
|
||||
if (varargElementType != null) {
|
||||
if (useTypeTable()) {
|
||||
builder.varargElementTypeId = typeId(varargElementType)
|
||||
} else {
|
||||
builder.setVarargElementType(typeProto(varargElementType))
|
||||
}
|
||||
val varargElementType = parameter.returnTypeRef.coneType.varargElementType(session)
|
||||
if (useTypeTable()) {
|
||||
builder.varargElementTypeId = typeId(varargElementType)
|
||||
} else {
|
||||
builder.setVarargElementType(typeProto(varargElementType))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -544,7 +542,7 @@ class FirElementSerializer private constructor(
|
||||
fun typeId(type: ConeKotlinType): Int = typeTable[typeProto(type)]
|
||||
|
||||
internal fun typeProto(typeRef: FirTypeRef): ProtoBuf.Type.Builder {
|
||||
return typeProto((typeRef as FirResolvedTypeRef).type)
|
||||
return typeProto(typeRef.coneType)
|
||||
}
|
||||
|
||||
internal fun typeProto(type: ConeKotlinType): ProtoBuf.Type.Builder {
|
||||
|
||||
+3
-6
@@ -26,10 +26,7 @@ import org.jetbrains.kotlin.fir.typeContext
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.withReplacedConeType
|
||||
import org.jetbrains.kotlin.fir.serialization.FirElementSerializer
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirAnonymousFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinErrorType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.declarations.IrClass
|
||||
import org.jetbrains.kotlin.ir.declarations.IrField
|
||||
@@ -73,9 +70,9 @@ class FirJvmClassCodegen(
|
||||
conf: TypeApproximatorConfiguration = TypeApproximatorConfiguration.PublicDeclaration
|
||||
): FirTypeRef {
|
||||
val approximatedType = if (toSuper)
|
||||
approximator.approximateToSuperType(this.coneTypeUnsafe(), conf)
|
||||
approximator.approximateToSuperType(coneType, conf)
|
||||
else
|
||||
approximator.approximateToSubType(this.coneTypeUnsafe(), conf)
|
||||
approximator.approximateToSubType(coneType, conf)
|
||||
return withReplacedConeType(approximatedType as? ConeKotlinType)
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -135,7 +135,7 @@ open class FirJvmMangleComputer(
|
||||
|
||||
receiverTypeRef?.let {
|
||||
builder.appendSignature(MangleConstant.EXTENSION_RECEIVER_PREFIX)
|
||||
mangleType(builder, it.coneTypeUnsafe())
|
||||
mangleType(builder, it.coneType)
|
||||
}
|
||||
|
||||
valueParameters.collectForMangler(builder, MangleConstant.VALUE_PARAMETERS) {
|
||||
@@ -148,7 +148,7 @@ open class FirJvmMangleComputer(
|
||||
}
|
||||
|
||||
if (!isCtor && !returnTypeRef.isUnit && addReturnType()) {
|
||||
mangleType(builder, returnTypeRef.coneTypeUnsafe())
|
||||
mangleType(builder, returnTypeRef.coneType)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ open class FirJvmMangleComputer(
|
||||
}
|
||||
|
||||
private fun mangleValueParameter(vpBuilder: StringBuilder, param: FirValueParameter) {
|
||||
mangleType(vpBuilder, param.returnTypeRef.coneTypeUnsafe())
|
||||
mangleType(vpBuilder, param.returnTypeRef.coneType)
|
||||
|
||||
if (param.isVararg) {
|
||||
vpBuilder.appendSignature(MangleConstant.VAR_ARG_MARK)
|
||||
@@ -182,7 +182,7 @@ open class FirJvmMangleComputer(
|
||||
tpBuilder.appendSignature(index)
|
||||
tpBuilder.appendSignature(MangleConstant.UPPER_BOUND_SEPARATOR)
|
||||
|
||||
param.bounds.map { it.coneTypeUnsafe<ConeKotlinType>() }.collectForMangler(tpBuilder, MangleConstant.UPPER_BOUNDS) {
|
||||
param.bounds.map { it.coneType }.collectForMangler(tpBuilder, MangleConstant.UPPER_BOUNDS) {
|
||||
mangleType(this, it)
|
||||
}
|
||||
}
|
||||
@@ -262,7 +262,7 @@ open class FirJvmMangleComputer(
|
||||
|
||||
property.receiverTypeRef?.let {
|
||||
builder.appendSignature(MangleConstant.EXTENSION_RECEIVER_PREFIX)
|
||||
mangleType(builder, it.coneTypeUnsafe())
|
||||
mangleType(builder, it.coneType)
|
||||
}
|
||||
|
||||
property.typeParameters.withIndex().toList().collectForMangler(builder, MangleConstant.TYPE_PARAMETERS) { (index, typeParameter) ->
|
||||
|
||||
+2
-2
@@ -239,8 +239,8 @@ class FirJvmSerializerExtension @JvmOverloads constructor(
|
||||
private fun FirFunction<*>.needsInlineParameterNullCheckRequirement(): Boolean =
|
||||
this is FirSimpleFunction && isInline && !isSuspend && !isParamAssertionsDisabled &&
|
||||
!Visibilities.isPrivate(visibility) &&
|
||||
(valueParameters.any { it.returnTypeRef.coneTypeSafe<ConeKotlinType>()?.isBuiltinFunctionalType(session) == true } ||
|
||||
receiverTypeRef?.coneTypeSafe<ConeKotlinType>()?.isBuiltinFunctionalType(session) == true)
|
||||
(valueParameters.any { it.returnTypeRef.coneType.isBuiltinFunctionalType(session) } ||
|
||||
receiverTypeRef?.coneType?.isBuiltinFunctionalType(session) == true)
|
||||
|
||||
override fun serializeProperty(
|
||||
property: FirProperty,
|
||||
|
||||
@@ -100,7 +100,7 @@ fun FirClassifierSymbol<*>.toSymbol(
|
||||
}
|
||||
is FirTypeAliasSymbol -> {
|
||||
val typeAlias = fir
|
||||
val coneClassLikeType = (typeAlias.expandedTypeRef as FirResolvedTypeRef).type as ConeClassLikeType
|
||||
val coneClassLikeType = typeAlias.expandedTypeRef.coneType as ConeClassLikeType
|
||||
coneClassLikeType.lookupTag.toSymbol(session)!!.toSymbol(session, classifierStorage)
|
||||
}
|
||||
is FirClassSymbol -> {
|
||||
|
||||
+2
-2
@@ -85,7 +85,7 @@ class Fir2IrDeclarationStorage(
|
||||
return irFunction.valueParameters.size == firFunction.valueParameters.size &&
|
||||
irFunction.valueParameters.zip(firFunction.valueParameters).all { (irParameter, firParameter) ->
|
||||
val irType = irParameter.type
|
||||
val firType = (firParameter.returnTypeRef as FirResolvedTypeRef).type
|
||||
val firType = firParameter.returnTypeRef.coneType
|
||||
if (irType is IrSimpleType) {
|
||||
when (val irClassifierSymbol = irType.classifier) {
|
||||
is IrTypeParameterSymbol -> {
|
||||
@@ -741,7 +741,7 @@ class Fir2IrDeclarationStorage(
|
||||
startOffset, endOffset, origin, symbol,
|
||||
valueParameter.name, index, type,
|
||||
if (!valueParameter.isVararg) null
|
||||
else valueParameter.returnTypeRef.coneTypeSafe<ConeKotlinType>()?.arrayElementType()?.toIrType(typeContext),
|
||||
else valueParameter.returnTypeRef.coneType.arrayElementType()?.toIrType(typeContext),
|
||||
valueParameter.isCrossinline, valueParameter.isNoinline
|
||||
).apply {
|
||||
descriptor.bind(this)
|
||||
|
||||
@@ -298,7 +298,7 @@ class Fir2IrVisitor(
|
||||
val afterNotNullCheck = safeCallExpression.regularQualifiedAccess.accept(this, data) as IrExpression
|
||||
|
||||
val isReceiverNullable = with(components.session.typeContext) {
|
||||
safeCallExpression.receiver.typeRef.coneTypeSafe<ConeKotlinType>()?.isNullableType() == true
|
||||
safeCallExpression.receiver.typeRef.coneType.isNullableType()
|
||||
}
|
||||
|
||||
components.createSafeCallConstruction(
|
||||
|
||||
@@ -29,8 +29,8 @@ fun FirComparisonExpression.inferPrimitiveNumericComparisonInfo(): PrimitiveCone
|
||||
inferPrimitiveNumericComparisonInfo(left, right)
|
||||
|
||||
fun inferPrimitiveNumericComparisonInfo(left: FirExpression, right: FirExpression): PrimitiveConeNumericComparisonInfo? {
|
||||
val leftType = left.typeRef.coneTypeSafe<ConeKotlinType>() ?: return null
|
||||
val rightType = right.typeRef.coneTypeSafe<ConeKotlinType>() ?: return null
|
||||
val leftType = left.typeRef.coneType
|
||||
val rightType = right.typeRef.coneType
|
||||
val leftPrimitiveOrNullableType = leftType.getPrimitiveTypeOrSupertype() ?: return null
|
||||
val rightPrimitiveOrNullableType = rightType.getPrimitiveTypeOrSupertype() ?: return null
|
||||
val leastCommonType = leastCommonPrimitiveNumericType(leftPrimitiveOrNullableType, rightPrimitiveOrNullableType)
|
||||
@@ -62,7 +62,7 @@ private fun ConeKotlinType.getPrimitiveTypeOrSupertype(): ConeClassLikeType? =
|
||||
when {
|
||||
this is ConeTypeParameterType ->
|
||||
this.lookupTag.typeParameterSymbol.fir.bounds.firstNotNullResult {
|
||||
it.coneTypeSafe<ConeKotlinType>()?.getPrimitiveTypeOrSupertype()
|
||||
it.coneType.getPrimitiveTypeOrSupertype()
|
||||
}
|
||||
this is ConeClassLikeType && isPrimitiveNumberType() ->
|
||||
this
|
||||
|
||||
+3
-4
@@ -251,7 +251,7 @@ class CallAndReferenceGenerator(
|
||||
}
|
||||
|
||||
fun convertToIrConstructorCall(annotationCall: FirAnnotationCall): IrExpression {
|
||||
val coneType = (annotationCall.annotationTypeRef as? FirResolvedTypeRef)?.type as? ConeLookupTagBasedType
|
||||
val coneType = annotationCall.annotationTypeRef.coneTypeSafe<ConeLookupTagBasedType>()
|
||||
val firSymbol = coneType?.lookupTag?.toSymbol(session) as? FirClassSymbol
|
||||
val type = coneType?.toIrType()
|
||||
val symbol = type?.classifierOrNull
|
||||
@@ -292,8 +292,7 @@ class CallAndReferenceGenerator(
|
||||
}
|
||||
|
||||
internal fun convertToGetObject(qualifier: FirResolvedQualifier, callableReferenceMode: Boolean): IrExpression? {
|
||||
val typeRef = qualifier.typeRef as? FirResolvedTypeRef
|
||||
val classSymbol = (typeRef?.type as? ConeClassLikeType)?.lookupTag?.toSymbol(session)
|
||||
val classSymbol = (qualifier.typeRef.coneType as? ConeClassLikeType)?.lookupTag?.toSymbol(session)
|
||||
if (callableReferenceMode && classSymbol is FirRegularClassSymbol) {
|
||||
if (classSymbol.classId != qualifier.classId) {
|
||||
return null
|
||||
@@ -428,7 +427,7 @@ class CallAndReferenceGenerator(
|
||||
|
||||
private fun needSamConversion(argument: FirExpression, parameter: FirValueParameter): Boolean {
|
||||
// If the expected type is a built-in functional type, we don't need SAM conversion.
|
||||
if (parameter.returnTypeRef.coneTypeSafe<ConeKotlinType>()?.isBuiltinFunctionalType(session) == true) {
|
||||
if (parameter.returnTypeRef.coneType.isBuiltinFunctionalType(session)) {
|
||||
return false
|
||||
}
|
||||
// On the other hand, the actual type should be a functional type.
|
||||
|
||||
+2
-2
@@ -257,7 +257,7 @@ internal class ClassMemberGenerator(
|
||||
val firDispatchReceiver = dispatchReceiver
|
||||
return convertWithOffsets { startOffset, endOffset ->
|
||||
val irConstructorSymbol = declarationStorage.getIrFunctionSymbol(constructorSymbol) as IrConstructorSymbol
|
||||
val typeArguments = (constructedTypeRef as? FirResolvedTypeRef)?.type?.fullyExpandedType(session)?.typeArguments
|
||||
val typeArguments = constructedTypeRef.coneType.fullyExpandedType(session).typeArguments
|
||||
val constructor = constructorSymbol.fir
|
||||
if (constructor.isFromEnumClass || constructor.returnTypeRef.isEnum) {
|
||||
IrEnumConstructorCallImpl(
|
||||
@@ -277,7 +277,7 @@ internal class ClassMemberGenerator(
|
||||
)
|
||||
}.let {
|
||||
if (constructor.typeParameters.isNotEmpty()) {
|
||||
if (typeArguments?.isNotEmpty() == true) {
|
||||
if (typeArguments.isNotEmpty()) {
|
||||
for ((index, typeArgument) in typeArguments.withIndex()) {
|
||||
if (index >= constructor.typeParameters.size) break
|
||||
val irType = (typeArgument as ConeKotlinTypeProjection).type.toIrType()
|
||||
|
||||
@@ -221,7 +221,7 @@ private fun FirTypeParameter.getErasedUpperBound(
|
||||
): ConeKotlinType {
|
||||
if (this === potentiallyRecursiveTypeParameter) return defaultValue()
|
||||
|
||||
val firstUpperBound = this.bounds.first().coneTypeUnsafe<ConeKotlinType>()
|
||||
val firstUpperBound = this.bounds.first().coneType
|
||||
|
||||
return getErasedVersionOfFirstUpperBound(firstUpperBound, mutableSetOf(this, potentiallyRecursiveTypeParameter), defaultValue)
|
||||
}
|
||||
@@ -256,7 +256,7 @@ private fun getErasedVersionOfFirstUpperBound(
|
||||
val current = firstUpperBound.lookupTag.typeParameterSymbol.fir
|
||||
|
||||
if (alreadyVisitedParameters.add(current)) {
|
||||
val nextUpperBound = current.bounds.first().coneTypeUnsafe<ConeKotlinType>()
|
||||
val nextUpperBound = current.bounds.first().coneType
|
||||
getErasedVersionOfFirstUpperBound(nextUpperBound, alreadyVisitedParameters, defaultValue)
|
||||
} else {
|
||||
defaultValue()
|
||||
|
||||
@@ -119,7 +119,7 @@ private fun coneFlexibleOrSimpleType(
|
||||
// TODO: we need enhancement for type parameter bounds for this code to work properly
|
||||
// At this moment, this condition is always true
|
||||
if (lookupTag.typeParameterSymbol.fir.bounds.any {
|
||||
val type = (it as FirResolvedTypeRef).type
|
||||
val type = it.coneType
|
||||
type is ConeTypeParameterType || type.isNullable
|
||||
}
|
||||
) {
|
||||
|
||||
+2
-3
@@ -9,8 +9,7 @@ import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.AbstractConeCallConflictResolver
|
||||
import org.jetbrains.kotlin.fir.resolve.calls.Candidate
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.resolve.calls.results.FlatSignature
|
||||
import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator
|
||||
|
||||
@@ -55,7 +54,7 @@ class ConeEquivalentCallConflictResolver(
|
||||
): Boolean {
|
||||
if (first.symbol.callableId != second.symbol.callableId) return false
|
||||
if (first.isExpect != second.isExpect) return false
|
||||
if (first.receiverTypeRef?.coneTypeUnsafe<ConeKotlinType>() != second.receiverTypeRef?.coneTypeUnsafe()) {
|
||||
if (first.receiverTypeRef?.coneType != second.receiverTypeRef?.coneType) {
|
||||
return false
|
||||
}
|
||||
val firstSignature = createFlatSignature(firstCandidate, first)
|
||||
|
||||
@@ -108,7 +108,7 @@ private fun StringBuilder.appendConeType(coneType: ConeKotlinType) {
|
||||
}
|
||||
is ConeTypeParameterType -> {
|
||||
val representative = coneType.lookupTag.typeParameterSymbol.fir.bounds.firstOrNull {
|
||||
(it as? FirResolvedTypeRef)?.type is ConeClassLikeType
|
||||
it.coneType is ConeClassLikeType
|
||||
}
|
||||
if (representative == null || representative is FirImplicitNullableAnyTypeRef || representative is FirImplicitAnyTypeRef) {
|
||||
append("Ljava/lang/Object")
|
||||
|
||||
+1
-1
@@ -418,7 +418,7 @@ class DeclarationsConverter(
|
||||
delegatedSuperTypeRef = buildResolvedTypeRef {
|
||||
type = ConeClassLikeTypeImpl(
|
||||
implicitEnumType.type.lookupTag,
|
||||
arrayOf(selfType.coneTypeUnsafe()),
|
||||
arrayOf(selfType.type),
|
||||
isNullable = false
|
||||
)
|
||||
}
|
||||
|
||||
@@ -490,7 +490,7 @@ class RawFirBuilder(
|
||||
delegatedSuperTypeRef = buildResolvedTypeRef {
|
||||
type = ConeClassLikeTypeImpl(
|
||||
implicitEnumType.type.lookupTag,
|
||||
delegatedSelfTypeRef?.coneTypeUnsafe<ConeKotlinType>()?.let { arrayOf(it) } ?: emptyArray(),
|
||||
delegatedSelfTypeRef?.coneType?.let { arrayOf(it) } ?: emptyArray(),
|
||||
isNullable = false,
|
||||
)
|
||||
}
|
||||
|
||||
+3
-4
@@ -132,7 +132,7 @@ class FirDoubleColonExpressionResolver(
|
||||
}
|
||||
|
||||
private fun resolveExpressionOnLHS(expression: FirExpression): DoubleColonLHS.Expression? {
|
||||
val type = (expression.typeRef as? FirResolvedTypeRef)?.type ?: return null
|
||||
val type = expression.typeRef.coneType
|
||||
|
||||
if (expression is FirResolvedQualifier) {
|
||||
val firClass = expression.expandedRegularClassIfAny() ?: return null
|
||||
@@ -161,9 +161,8 @@ class FirDoubleColonExpressionResolver(
|
||||
if (typeArgument == null) ConeStarProjection
|
||||
else when (typeArgument) {
|
||||
is FirTypeProjectionWithVariance -> {
|
||||
val coneType = typeArgument.typeRef.coneTypeSafe<ConeKotlinType>()
|
||||
if (coneType == null) ConeStarProjection
|
||||
else when (typeArgument.variance) {
|
||||
val coneType = typeArgument.typeRef.coneType
|
||||
when (typeArgument.variance) {
|
||||
Variance.INVARIANT -> coneType
|
||||
Variance.IN_VARIANCE -> ConeKotlinTypeProjectionIn(coneType)
|
||||
Variance.OUT_VARIANCE -> ConeKotlinTypeProjectionOut(coneType)
|
||||
|
||||
@@ -217,9 +217,9 @@ fun FirFunction<*>.constructFunctionalTypeRef(isSuspend: Boolean = false): FirRe
|
||||
val parameters = valueParameters.map {
|
||||
it.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType("No type for parameter")
|
||||
}
|
||||
val rawReturnType = (this as FirTypedDeclaration).returnTypeRef.coneTypeUnsafe<ConeKotlinType>()
|
||||
val rawReturnType = (this as FirTypedDeclaration).returnTypeRef.coneType
|
||||
|
||||
val functionalType = createFunctionalType(parameters, receiverTypeRef?.coneTypeSafe(), rawReturnType, isSuspend = isSuspend)
|
||||
val functionalType = createFunctionalType(parameters, receiverTypeRef?.coneType, rawReturnType, isSuspend = isSuspend)
|
||||
|
||||
return buildResolvedTypeRef {
|
||||
source = this@constructFunctionalTypeRef.source?.withKind(FirFakeSourceElementKind.ImplicitTypeRef)
|
||||
@@ -362,13 +362,13 @@ fun <T : FirResolvable> BodyResolveComponents.typeFromCallee(access: T): FirReso
|
||||
private fun BodyResolveComponents.typeFromSymbol(symbol: AbstractFirBasedSymbol<*>, makeNullable: Boolean): FirResolvedTypeRef {
|
||||
return when (symbol) {
|
||||
is FirCallableSymbol<*> -> {
|
||||
val returnType = returnTypeCalculator.tryCalculateReturnType(symbol.phasedFir)
|
||||
val returnTypeRef = returnTypeCalculator.tryCalculateReturnType(symbol.phasedFir)
|
||||
if (makeNullable) {
|
||||
returnType.withReplacedConeType(
|
||||
returnType.coneTypeUnsafe<ConeKotlinType>().withNullability(ConeNullability.NULLABLE, session.typeContext),
|
||||
returnTypeRef.withReplacedConeType(
|
||||
returnTypeRef.type.withNullability(ConeNullability.NULLABLE, session.typeContext),
|
||||
)
|
||||
} else {
|
||||
returnType
|
||||
returnTypeRef
|
||||
}
|
||||
}
|
||||
is FirClassifierSymbol<*> -> {
|
||||
@@ -385,7 +385,7 @@ private fun BodyResolveComponents.typeFromSymbol(symbol: AbstractFirBasedSymbol<
|
||||
fun BodyResolveComponents.transformQualifiedAccessUsingSmartcastInfo(qualifiedAccessExpression: FirQualifiedAccessExpression): FirQualifiedAccessExpression {
|
||||
val typesFromSmartCast = dataFlowAnalyzer.getTypeUsingSmartcastInfo(qualifiedAccessExpression) ?: return qualifiedAccessExpression
|
||||
val allTypes = typesFromSmartCast.also {
|
||||
it += qualifiedAccessExpression.resultType.coneTypeUnsafe<ConeKotlinType>()
|
||||
it += qualifiedAccessExpression.resultType.coneType
|
||||
}
|
||||
val intersectedType = ConeTypeIntersector.intersectTypes(inferenceComponents.ctx, allTypes)
|
||||
// TODO: add check that intersectedType is not equal to original type
|
||||
@@ -463,7 +463,7 @@ private fun FirQualifiedAccess.expressionTypeOrUnitForAssignment(): ConeKotlinTy
|
||||
}
|
||||
|
||||
fun FirAnnotationCall.getCorrespondingConstructorReferenceOrNull(session: FirSession): FirResolvedNamedReference? =
|
||||
annotationTypeRef.coneTypeSafe<ConeKotlinType>()?.classId?.let {
|
||||
annotationTypeRef.coneType.classId?.let {
|
||||
(session.firSymbolProvider.getClassLikeSymbolByFqName(it) as? FirRegularClassSymbol)?.fir
|
||||
?.getPrimaryConstructorIfAny()
|
||||
?.let { annotationConstructor ->
|
||||
|
||||
@@ -148,7 +148,7 @@ class FirSamResolverImpl(
|
||||
newTypeParameter.bounds += declared.bounds.mapNotNull { typeRef ->
|
||||
buildResolvedTypeRef {
|
||||
source = typeRef.source
|
||||
type = substitutor.substituteOrSelf(typeRef.coneTypeSafe() ?: return@mapNotNull null)
|
||||
type = substitutor.substituteOrSelf(typeRef.coneType)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -333,9 +333,7 @@ fun FirSimpleFunction.isPublicInObject(checkOnlyName: Boolean): Boolean {
|
||||
}
|
||||
|
||||
private fun FirValueParameter.hasTypeOf(classId: ClassId, allowNullable: Boolean): Boolean {
|
||||
val type = returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: return false
|
||||
|
||||
val classLike = when (type) {
|
||||
val classLike = when (val type = returnTypeRef.coneType) {
|
||||
is ConeClassLikeType -> type
|
||||
is ConeFlexibleType -> type.upperBound as? ConeClassLikeType ?: return false
|
||||
else -> return false
|
||||
@@ -354,7 +352,7 @@ private fun FirSimpleFunction.getFunctionTypeForAbstractMethod(): ConeLookupTagB
|
||||
|
||||
return createFunctionalType(
|
||||
parameterTypes, receiverType = null,
|
||||
rawReturnType = returnTypeRef.coneTypeSafe() ?: ConeKotlinErrorType("No type for return type of $this"),
|
||||
rawReturnType = returnTypeRef.coneType,
|
||||
isSuspend = this.isSuspend
|
||||
)
|
||||
}
|
||||
|
||||
@@ -37,7 +37,7 @@ fun ConeKotlinType.scope(useSiteSession: FirSession, scopeSession: ScopeSession)
|
||||
useSiteSession,
|
||||
FirStandardOverrideChecker(useSiteSession),
|
||||
fir.bounds.mapNotNullTo(mutableListOf()) {
|
||||
it.coneTypeUnsafe<ConeKotlinType>().scope(useSiteSession, scopeSession)
|
||||
it.coneType.scope(useSiteSession, scopeSession)
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -67,7 +67,7 @@ fun createSubstitution(
|
||||
else /* StarProjection */ -> {
|
||||
ConeTypeIntersector.intersectTypes(
|
||||
session.typeContext,
|
||||
typeParameterSymbol.fir.bounds.map { it.coneTypeUnsafe() }
|
||||
typeParameterSymbol.fir.bounds.map { it.coneType }
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+4
-7
@@ -8,10 +8,7 @@ package org.jetbrains.kotlin.fir.resolve.calls
|
||||
import org.jetbrains.kotlin.fir.declarations.*
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
import org.jetbrains.kotlin.fir.symbols.StandardClassIds
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.arrayElementType
|
||||
import org.jetbrains.kotlin.fir.types.classId
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.resolve.calls.results.*
|
||||
import org.jetbrains.kotlin.types.checker.requireOrDescribe
|
||||
import org.jetbrains.kotlin.types.model.KotlinTypeMarker
|
||||
@@ -112,7 +109,7 @@ abstract class AbstractConeCallConflictResolver(
|
||||
return FlatSignature(
|
||||
call,
|
||||
(variable as? FirProperty)?.typeParameters?.map { it.symbol }.orEmpty(),
|
||||
listOfNotNull(variable.receiverTypeRef?.coneTypeUnsafe()),
|
||||
listOfNotNull(variable.receiverTypeRef?.coneType),
|
||||
variable.receiverTypeRef != null,
|
||||
false,
|
||||
0,
|
||||
@@ -149,7 +146,7 @@ abstract class AbstractConeCallConflictResolver(
|
||||
}
|
||||
|
||||
private fun FirValueParameter.argumentType(): ConeKotlinType {
|
||||
val type = returnTypeRef.coneTypeUnsafe<ConeKotlinType>()
|
||||
val type = returnTypeRef.coneType
|
||||
if (isVararg) return type.arrayElementType()!!
|
||||
return type
|
||||
}
|
||||
@@ -158,7 +155,7 @@ abstract class AbstractConeCallConflictResolver(
|
||||
call: Candidate,
|
||||
function: FirFunction<*>
|
||||
): List<ConeKotlinType> {
|
||||
return listOfNotNull(function.receiverTypeRef?.coneTypeUnsafe()) +
|
||||
return listOfNotNull(function.receiverTypeRef?.coneType) +
|
||||
(call.resultingTypeForCallableReference?.typeArguments?.map { it as ConeKotlinType }
|
||||
?: call.argumentMapping?.map { it.value.argumentType() }.orEmpty())
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ private fun Candidate.resolveBlockArgument(
|
||||
if (returnArguments.isEmpty()) {
|
||||
checkApplicabilityForArgumentType(
|
||||
csBuilder,
|
||||
block.typeRef.coneTypeUnsafe(),
|
||||
block.typeRef.coneType,
|
||||
expectedType?.type,
|
||||
SimpleConstraintSystemConstraintPosition,
|
||||
isReceiver = false,
|
||||
@@ -177,9 +177,9 @@ fun Candidate.resolveSubCallArgument(
|
||||
* placeholder type with value 0, but argument contains type with proper literal value
|
||||
*/
|
||||
val type: ConeKotlinType = if (candidate.symbol.fir is FirIntegerOperator) {
|
||||
(argument as FirFunctionCall).resultType.coneTypeUnsafe()
|
||||
(argument as FirFunctionCall).resultType.coneType
|
||||
} else {
|
||||
sink.components.returnTypeCalculator.tryCalculateReturnType(candidate.symbol.firUnsafe()).coneTypeUnsafe()
|
||||
sink.components.returnTypeCalculator.tryCalculateReturnType(candidate.symbol.firUnsafe()).type
|
||||
}
|
||||
val argumentType = candidate.substitutor.substituteOrSelf(type)
|
||||
resolvePlainArgumentType(csBuilder, argumentType, expectedType, sink, isReceiver, isDispatch, useNullableArgumentType)
|
||||
@@ -308,7 +308,7 @@ internal fun Candidate.resolveArgument(
|
||||
|
||||
private fun Candidate.prepareExpectedType(session: FirSession, argument: FirExpression, parameter: FirValueParameter?): ConeKotlinType? {
|
||||
if (parameter == null) return null
|
||||
if (parameter.returnTypeRef is FirILTTypeRefPlaceHolder) return argument.resultType.coneTypeUnsafe()
|
||||
if (parameter.returnTypeRef is FirILTTypeRefPlaceHolder) return argument.resultType.coneType
|
||||
val basicExpectedType = argument.getExpectedType(session, parameter/*, LanguageVersionSettings*/)
|
||||
val expectedType = getExpectedTypeWithSAMConversion(session, argument, basicExpectedType) ?: basicExpectedType
|
||||
return this.substitutor.substituteOrSelf(expectedType)
|
||||
@@ -350,9 +350,9 @@ internal fun FirExpression.getExpectedType(
|
||||
}
|
||||
|
||||
return if (parameter.isVararg && shouldUnwrapVarargType) {
|
||||
parameter.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().varargElementType(session)
|
||||
parameter.returnTypeRef.coneType.varargElementType(session)
|
||||
} else {
|
||||
parameter.returnTypeRef.coneTypeUnsafe()
|
||||
parameter.returnTypeRef.coneType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -13,7 +13,7 @@ import org.jetbrains.kotlin.fir.resolve.inference.InferenceComponents
|
||||
import org.jetbrains.kotlin.fir.resolve.inference.TypeParameterBasedTypeVariable
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.substitutorByMap
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeParameterSymbol
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.NewConstraintSystemImpl
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.model.SimpleConstraintSystemConstraintPosition
|
||||
import org.jetbrains.kotlin.resolve.calls.results.FlatSignature
|
||||
@@ -192,7 +192,7 @@ class ConeSimpleConstraintSystemImpl(val system: NewConstraintSystemImpl) : Simp
|
||||
for (upperBound in typeParameter.fir.bounds) {
|
||||
addSubtypeConstraint(
|
||||
substitutionMap[typeParameter] ?: error("No ${typeParameter.fir.render()} in substitution map"),
|
||||
substitutor.substituteOrSelf(upperBound.coneTypeUnsafe())
|
||||
substitutor.substituteOrSelf(upperBound.coneType)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+3
-2
@@ -22,6 +22,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeClassLikeType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
private operator fun <T> Pair<T, *>?.component1() = this?.first
|
||||
@@ -215,10 +216,10 @@ private class TypeAliasConstructorsSubstitutor<F : FirFunction<F>>(
|
||||
) {
|
||||
fun substitute(baseFunction: F): F {
|
||||
val typeParameters = typeAliasSymbol.fir.typeParameters
|
||||
val newReturnType = baseFunction.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().let(substitutor::substituteOrNull)
|
||||
val newReturnType = baseFunction.returnTypeRef.coneType.let(substitutor::substituteOrNull)
|
||||
|
||||
val newParameterTypes = baseFunction.valueParameters.map { valueParameter ->
|
||||
valueParameter.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().let(substitutor::substituteOrNull)
|
||||
valueParameter.returnTypeRef.coneType.let(substitutor::substituteOrNull)
|
||||
}
|
||||
|
||||
if (newReturnType == null && newParameterTypes.all { it == null }) return baseFunction
|
||||
|
||||
+4
-4
@@ -64,7 +64,7 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
||||
is FirTypeProjectionWithVariance -> csBuilder.addEqualityConstraint(
|
||||
freshVariable.defaultType,
|
||||
getTypePreservingFlexibilityWrtTypeVariable(
|
||||
typeArgument.typeRef.coneTypeUnsafe(),
|
||||
typeArgument.typeRef.coneType,
|
||||
typeParameter,
|
||||
candidate.bodyResolveComponents.inferenceComponents.ctx
|
||||
),
|
||||
@@ -72,7 +72,7 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
||||
)
|
||||
is FirStarProjection -> csBuilder.addEqualityConstraint(
|
||||
freshVariable.defaultType,
|
||||
typeParameter.symbol.fir.bounds.firstOrNull()?.coneTypeUnsafe()
|
||||
typeParameter.symbol.fir.bounds.firstOrNull()?.coneType
|
||||
?: sink.components.session.builtinTypes.nullableAnyType.type,
|
||||
SimpleConstraintSystemConstraintPosition
|
||||
)
|
||||
@@ -98,7 +98,7 @@ internal object CreateFreshTypeVariableSubstitutorStage : ResolutionStage() {
|
||||
|
||||
private fun FirTypeParameterRef.shouldBeFlexible(context: ConeTypeContext): Boolean {
|
||||
return symbol.fir.bounds.any {
|
||||
val type = it.coneTypeUnsafe<ConeKotlinType>()
|
||||
val type = it.coneType
|
||||
type is ConeFlexibleType || with(context) {
|
||||
(type.typeConstructor() as? FirTypeParameterSymbol)?.fir?.shouldBeFlexible(context) ?: false
|
||||
}
|
||||
@@ -147,7 +147,7 @@ private fun createToFreshVariableSubstitutorAndAddInitialConstraints(
|
||||
//val position = DeclaredUpperBoundConstraintPosition(typeParameter)
|
||||
|
||||
for (upperBound in typeParameter.symbol.fir.bounds) {
|
||||
freshVariable.addSubtypeConstraint(upperBound.coneTypeUnsafe()/*, position*/)
|
||||
freshVariable.addSubtypeConstraint(upperBound.coneType/*, position*/)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@ abstract class AbstractExplicitReceiver<E : FirExpression> : Receiver {
|
||||
|
||||
abstract class AbstractExplicitReceiverValue<E : FirExpression> : AbstractExplicitReceiver<E>(), ReceiverValue {
|
||||
override val type: ConeKotlinType
|
||||
// NB: safe cast is necessary here
|
||||
get() = explicitReceiver.typeRef.coneTypeSafe()
|
||||
?: ConeKotlinErrorType("No type calculated for: ${explicitReceiver.renderWithType()}") // TODO: assert here
|
||||
|
||||
@@ -75,7 +76,7 @@ sealed class ImplicitReceiverValue<S : AbstractFirBasedSymbol<*>>(
|
||||
internal fun replaceType(type: ConeKotlinType) {
|
||||
if (type == this.type) return
|
||||
this.type = type
|
||||
receiverExpression = if (type == originalReceiverExpression.typeRef.coneTypeUnsafe()) {
|
||||
receiverExpression = if (type == originalReceiverExpression.typeRef.coneType) {
|
||||
originalReceiverExpression
|
||||
} else {
|
||||
buildExpressionWithSmartcast {
|
||||
|
||||
@@ -94,7 +94,7 @@ internal sealed class CheckReceivers : ResolutionStage() {
|
||||
override fun Candidate.getReceiverType(): ConeKotlinType? {
|
||||
val callableSymbol = symbol as? FirCallableSymbol<*> ?: return null
|
||||
val callable = callableSymbol.fir
|
||||
val receiverType = callable.receiverTypeRef?.coneTypeUnsafe<ConeKotlinType>()
|
||||
val receiverType = callable.receiverTypeRef?.coneType
|
||||
if (receiverType != null) return receiverType
|
||||
val returnTypeRef = callable.returnTypeRef as? FirResolvedTypeRef ?: return null
|
||||
if (!returnTypeRef.type.isExtensionFunctionType(bodyResolveComponents.session)) return null
|
||||
@@ -244,7 +244,7 @@ internal object CheckCallableReferenceExpectedType : CheckerStage() {
|
||||
}
|
||||
|
||||
val declarationReceiverType: ConeKotlinType? =
|
||||
(fir as? FirCallableMemberDeclaration<*>)?.receiverTypeRef?.coneTypeSafe<ConeKotlinType>()
|
||||
(fir as? FirCallableMemberDeclaration<*>)?.receiverTypeRef?.coneType
|
||||
?.let(candidate.substitutor::substituteOrSelf)
|
||||
|
||||
if (resultingReceiverType != null && declarationReceiverType != null) {
|
||||
@@ -273,7 +273,7 @@ private fun createKPropertyType(
|
||||
receiverType: ConeKotlinType?,
|
||||
returnTypeRef: FirResolvedTypeRef
|
||||
): ConeKotlinType {
|
||||
val propertyType = returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: ConeKotlinErrorType("No type for of $propertyOrField")
|
||||
val propertyType = returnTypeRef.type
|
||||
return createKPropertyType(
|
||||
receiverType, propertyType, isMutable = propertyOrField.isVar
|
||||
)
|
||||
@@ -296,8 +296,7 @@ private fun FirSession.createKFunctionType(
|
||||
}
|
||||
for ((index, valueParameter) in function.valueParameters.withIndex()) {
|
||||
if (expectedParameterNumber == null || index < expectedParameterNumber || valueParameter.defaultValue == null) {
|
||||
parameterTypes += valueParameter.returnTypeRef.coneTypeSafe()
|
||||
?: ConeKotlinErrorType("No type for parameter $valueParameter")
|
||||
parameterTypes += valueParameter.returnTypeRef.coneType
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +304,7 @@ private fun FirSession.createKFunctionType(
|
||||
if (expectedReturnType != null && typeContext.run { expectedReturnType.isUnit() })
|
||||
expectedReturnType
|
||||
else
|
||||
returnTypeRef.coneTypeSafe() ?: ConeKotlinErrorType("No type for return type of $function")
|
||||
returnTypeRef.type
|
||||
|
||||
return createFunctionalType(
|
||||
parameterTypes, receiverType = receiverType,
|
||||
@@ -532,7 +531,7 @@ internal object PostponedVariablesInitializerResolutionStage : ResolutionStage()
|
||||
if (candidate.typeArgumentMapping is TypeArgumentMapping.Mapped) return
|
||||
for (parameter in argumentMapping.values) {
|
||||
if (!parameter.hasBuilderInferenceMarker()) continue
|
||||
val type = parameter.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: continue
|
||||
val type = parameter.returnTypeRef.coneType
|
||||
val receiverType = type.receiverType(callInfo.session) ?: continue
|
||||
|
||||
for (freshVariable in candidate.freshVariables) {
|
||||
|
||||
+1
-3
@@ -201,9 +201,7 @@ private class TowerScopeLevelProcessor(
|
||||
val extensionReceiverType = explicitReceiver?.typeRef?.coneTypeSafe()
|
||||
?: implicitExtensionReceiverValue?.type as? ConeClassLikeType
|
||||
if (extensionReceiverType != null) {
|
||||
val declarationReceiverTypeRef =
|
||||
(symbol as? FirCallableSymbol<*>)?.fir?.receiverTypeRef as? FirResolvedTypeRef
|
||||
val declarationReceiverType = declarationReceiverTypeRef?.type
|
||||
val declarationReceiverType = (symbol as? FirCallableSymbol<*>)?.fir?.receiverTypeRef?.coneType
|
||||
if (declarationReceiverType is ConeClassLikeType) {
|
||||
if (!AbstractTypeChecker.isSubtypeOf(
|
||||
candidateFactory.bodyResolveComponents.inferenceComponents.ctx,
|
||||
|
||||
+7
-8
@@ -103,8 +103,8 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
|
||||
|
||||
private var contractDescriptionVisitingMode = false
|
||||
|
||||
protected val any = components.session.builtinTypes.anyType.coneTypeUnsafe<ConeKotlinType>()
|
||||
private val nullableNothing = components.session.builtinTypes.nullableNothingType.coneTypeUnsafe<ConeKotlinType>()
|
||||
protected val any = components.session.builtinTypes.anyType.type
|
||||
private val nullableNothing = components.session.builtinTypes.nullableNothingType.type
|
||||
|
||||
// ----------------------------------- Requests -----------------------------------
|
||||
|
||||
@@ -263,7 +263,7 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
|
||||
fun exitTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall) {
|
||||
val node = graphBuilder.exitTypeOperatorCall(typeOperatorCall).mergeIncomingFlow()
|
||||
if (typeOperatorCall.operation !in FirOperation.TYPES) return
|
||||
val type = typeOperatorCall.conversionTypeRef.coneTypeUnsafe<ConeKotlinType>()
|
||||
val type = typeOperatorCall.conversionTypeRef.coneType
|
||||
val operandVariable = variableStorage.getOrCreateVariable(node.previousFlow, typeOperatorCall.argument)
|
||||
val flow = node.flow
|
||||
|
||||
@@ -388,8 +388,8 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
|
||||
}
|
||||
|
||||
private fun processEq(node: OperatorCallNode, leftOperand: FirExpression, rightOperand: FirExpression, operation: FirOperation) {
|
||||
val leftIsNullable = leftOperand.coneType?.isMarkedNullable ?: return
|
||||
val rightIsNullable = rightOperand.coneType?.isMarkedNullable ?: return
|
||||
val leftIsNullable = leftOperand.coneType.isMarkedNullable
|
||||
val rightIsNullable = rightOperand.coneType.isMarkedNullable
|
||||
// left == right && right not null -> left != null
|
||||
when {
|
||||
leftIsNullable && rightIsNullable -> return
|
||||
@@ -638,8 +638,7 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
|
||||
}
|
||||
|
||||
safeCall.receiver.let { receiver ->
|
||||
val type = receiver.coneType
|
||||
?.takeIf { it.isMarkedNullable }
|
||||
val type = receiver.coneType.takeIf { it.isMarkedNullable }
|
||||
?.withNullability(ConeNullability.NOT_NULL)
|
||||
?: return@let
|
||||
|
||||
@@ -837,7 +836,7 @@ abstract class FirDataFlowAnalyzer<FLOW : Flow>(
|
||||
|
||||
if (isAssignment) {
|
||||
if (initializer is FirConstExpression<*> && initializer.kind == FirConstKind.Null) return
|
||||
flow.addTypeStatement(propertyVariable typeEq initializer.typeRef.coneTypeUnsafe())
|
||||
flow.addTypeStatement(propertyVariable typeEq initializer.typeRef.coneType)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirAccessorSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirNamedFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.utils.addToStdlib.safeAs
|
||||
import kotlin.contracts.ExperimentalContracts
|
||||
import kotlin.contracts.InvocationKind
|
||||
@@ -88,8 +88,8 @@ internal fun ConeConstantReference.toOperation(): Operation = when (this) {
|
||||
}
|
||||
|
||||
@DfaInternals
|
||||
internal val FirExpression.coneType: ConeKotlinType?
|
||||
get() = typeRef.coneTypeSafe()
|
||||
internal val FirExpression.coneType: ConeKotlinType
|
||||
get() = typeRef.coneType
|
||||
|
||||
@DfaInternals
|
||||
internal val FirElement.symbol: AbstractFirBasedSymbol<*>?
|
||||
|
||||
+7
-10
@@ -19,10 +19,7 @@ import org.jetbrains.kotlin.fir.resolve.calls.FirNamedReferenceWithCandidate
|
||||
import org.jetbrains.kotlin.fir.resolve.defaultType
|
||||
import org.jetbrains.kotlin.fir.resolve.substitution.ConeSubstitutor
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirFunctionSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.ConeTypeVariableTypeConstructor
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.ConstraintSystemBuilder
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.NewConstraintSystem
|
||||
import org.jetbrains.kotlin.resolve.calls.inference.buildAbstractResultingSubstitutor
|
||||
@@ -49,7 +46,7 @@ class FirDelegatedPropertyInferenceSession(
|
||||
}
|
||||
|
||||
val expectedType: ConeKotlinType? by lazy { property.returnTypeRef.coneTypeSafe() }
|
||||
private val unitType: ConeKotlinType = components.session.builtinTypes.unitType.coneTypeUnsafe()
|
||||
private val unitType: ConeKotlinType = components.session.builtinTypes.unitType.type
|
||||
private lateinit var resultingConstraintSystem: NewConstraintSystem
|
||||
|
||||
override fun <T> shouldRunCompletion(call: T): Boolean where T : FirResolvable, T : FirStatement = false
|
||||
@@ -106,7 +103,7 @@ class FirDelegatedPropertyInferenceSession(
|
||||
private fun Candidate.addConstraintsForGetValueMethod(commonSystem: ConstraintSystemBuilder) {
|
||||
if (expectedType != null) {
|
||||
val accessor = symbol.fir as? FirSimpleFunction ?: return
|
||||
val unsubstitutedReturnType = accessor.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: return
|
||||
val unsubstitutedReturnType = accessor.returnTypeRef.coneType
|
||||
|
||||
val substitutedReturnType = substitutor.substituteOrSelf(unsubstitutedReturnType)
|
||||
commonSystem.addSubtypeConstraint(substitutedReturnType, expectedType!!, SimpleConstraintSystemConstraintPosition)
|
||||
@@ -118,7 +115,7 @@ class FirDelegatedPropertyInferenceSession(
|
||||
private fun Candidate.addConstraintsForSetValueMethod(commonSystem: ConstraintSystemBuilder) {
|
||||
if (expectedType != null) {
|
||||
val accessor = symbol.fir as? FirSimpleFunction ?: return
|
||||
val unsubstitutedParameterType = accessor.valueParameters.getOrNull(2)?.returnTypeRef?.coneTypeSafe<ConeKotlinType>() ?: return
|
||||
val unsubstitutedParameterType = accessor.valueParameters.getOrNull(2)?.returnTypeRef?.coneType ?: return
|
||||
|
||||
val substitutedReturnType = substitutor.substituteOrSelf(unsubstitutedParameterType)
|
||||
commonSystem.addSubtypeConstraint(substitutedReturnType, expectedType!!, SimpleConstraintSystemConstraintPosition)
|
||||
@@ -128,14 +125,14 @@ class FirDelegatedPropertyInferenceSession(
|
||||
}
|
||||
|
||||
private fun Candidate.addConstraintForThis(commonSystem: ConstraintSystemBuilder) {
|
||||
val typeOfThis: ConeKotlinType = property.receiverTypeRef?.coneTypeUnsafe()
|
||||
val typeOfThis: ConeKotlinType = property.receiverTypeRef?.coneType
|
||||
?: when (val container = components.container) {
|
||||
is FirRegularClass -> container.defaultType()
|
||||
is FirAnonymousObject -> container.defaultType()
|
||||
else -> null
|
||||
} ?: components.session.builtinTypes.nullableNothingType.coneTypeUnsafe()
|
||||
} ?: components.session.builtinTypes.nullableNothingType.type
|
||||
val valueParameterForThis = (symbol as? FirFunctionSymbol<*>)?.fir?.valueParameters?.firstOrNull() ?: return
|
||||
val substitutedType = substitutor.substituteOrSelf(valueParameterForThis.returnTypeRef.coneTypeUnsafe<ConeKotlinType>())
|
||||
val substitutedType = substitutor.substituteOrSelf(valueParameterForThis.returnTypeRef.coneType)
|
||||
commonSystem.addSubtypeConstraint(typeOfThis, substitutedType, SimpleConstraintSystemConstraintPosition)
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -89,9 +89,9 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver {
|
||||
|
||||
private fun createFunctionalType(typeRef: FirFunctionTypeRef): ConeClassLikeType {
|
||||
val parameters =
|
||||
listOfNotNull((typeRef.receiverTypeRef as FirResolvedTypeRef?)?.type) +
|
||||
typeRef.valueParameters.map { it.returnTypeRef.coneTypeUnsafe() } +
|
||||
listOf(typeRef.returnTypeRef.coneTypeUnsafe())
|
||||
listOfNotNull(typeRef.receiverTypeRef?.coneType) +
|
||||
typeRef.valueParameters.map { it.returnTypeRef.coneType } +
|
||||
listOf(typeRef.returnTypeRef.coneType)
|
||||
val classId = if (typeRef.isSuspend) {
|
||||
KotlinBuiltIns.getSuspendFunctionClassId(typeRef.parametersCount)
|
||||
} else {
|
||||
|
||||
+3
-4
@@ -282,7 +282,7 @@ class FirCallCompletionResultsWriterTransformer(
|
||||
qualifiedAccessExpression: FirQualifiedAccessExpression,
|
||||
data: Nothing?
|
||||
): CompositeTransformResult<FirStatement> {
|
||||
val originalType = qualifiedAccessExpression.typeRef.coneTypeUnsafe<ConeKotlinType>()
|
||||
val originalType = qualifiedAccessExpression.typeRef.coneType
|
||||
val substitutedReceiverType = finalSubstitutor.substituteOrNull(originalType) ?: return qualifiedAccessExpression.compose()
|
||||
qualifiedAccessExpression.replaceTypeRef(
|
||||
qualifiedAccessExpression.typeRef.resolvedTypeFromPrototype(substitutedReceiverType)
|
||||
@@ -292,8 +292,7 @@ class FirCallCompletionResultsWriterTransformer(
|
||||
}
|
||||
|
||||
private fun FirTypeRef.substitute(candidate: Candidate): ConeKotlinType =
|
||||
coneTypeUnsafe<ConeKotlinType>()
|
||||
.let { candidate.substitutor.substituteOrSelf(it) }
|
||||
coneType.let { candidate.substitutor.substituteOrSelf(it) }
|
||||
.let { finalSubstitutor.substituteOrSelf(it) }
|
||||
|
||||
private fun Candidate.createArgumentsMapping(): ExpectedArgumentType? {
|
||||
@@ -532,7 +531,7 @@ class FirDeclarationCompletionResultsWriter(private val finalSubstitutor: ConeSu
|
||||
}
|
||||
|
||||
override fun transformTypeRef(typeRef: FirTypeRef, data: Nothing?): CompositeTransformResult<FirTypeRef> {
|
||||
return finalSubstitutor.substituteOrNull(typeRef.coneTypeUnsafe())?.let {
|
||||
return finalSubstitutor.substituteOrNull(typeRef.coneType)?.let {
|
||||
typeRef.resolvedTypeFromPrototype(it)
|
||||
}?.compose() ?: typeRef.compose()
|
||||
}
|
||||
|
||||
+2
-2
@@ -17,8 +17,8 @@ import org.jetbrains.kotlin.fir.symbols.impl.FirClassifierSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirRegularClassSymbol
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.FirTypeAliasSymbol
|
||||
import org.jetbrains.kotlin.fir.types.ConeLookupTagBasedType
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
|
||||
import org.jetbrains.kotlin.fir.visitors.FirTransformer
|
||||
@@ -86,7 +86,7 @@ class FirSealedClassInheritorsTransformer : FirTransformer<Nothing?>() {
|
||||
}
|
||||
|
||||
private fun extractClassFromTypeRef(symbolProvider: FirSymbolProvider, typeRef: FirTypeRef): FirRegularClass? {
|
||||
val lookupTag = ((typeRef as FirResolvedTypeRef).type as? ConeLookupTagBasedType)?.lookupTag ?: return null
|
||||
val lookupTag = (typeRef.coneType as? ConeLookupTagBasedType)?.lookupTag ?: return null
|
||||
val classLikeSymbol: FirClassifierSymbol<*> = symbolProvider.getSymbolByLookupTag(lookupTag) ?: return null
|
||||
return when (classLikeSymbol) {
|
||||
is FirRegularClassSymbol -> classLikeSymbol.fir
|
||||
|
||||
+1
-2
@@ -197,8 +197,7 @@ private class FirSupertypeResolverVisitor(
|
||||
) {
|
||||
if (!visited.add(classLikeDeclaration)) return
|
||||
val supertypes =
|
||||
resolveSpecificClassLikeSupertypes(classLikeDeclaration, supertypeRefs)
|
||||
.mapNotNull { (it as? FirResolvedTypeRef)?.type }
|
||||
resolveSpecificClassLikeSupertypes(classLikeDeclaration, supertypeRefs).map { it.coneType }
|
||||
|
||||
for (supertype in supertypes) {
|
||||
if (supertype !is ConeClassLikeType) continue
|
||||
|
||||
+2
-2
@@ -185,7 +185,7 @@ class FirSyntheticCallGenerator(
|
||||
|
||||
val (typeParameter, returnType) = generateSyntheticSelectTypeParameter()
|
||||
|
||||
val argumentType = buildResolvedTypeRef { type = returnType.coneTypeUnsafe<ConeKotlinType>().createArrayOf() }
|
||||
val argumentType = buildResolvedTypeRef { type = returnType.type.createArrayOf() }
|
||||
val typeArgument = buildTypeProjectionWithVariance {
|
||||
typeRef = returnType
|
||||
variance = Variance.INVARIANT
|
||||
@@ -208,7 +208,7 @@ class FirSyntheticCallGenerator(
|
||||
val (typeParameter, returnType) = generateSyntheticSelectTypeParameter()
|
||||
|
||||
val argumentType = buildResolvedTypeRef {
|
||||
type = returnType.coneTypeUnsafe<ConeKotlinType>().withNullability(ConeNullability.NULLABLE, session.typeContext)
|
||||
type = returnType.type.withNullability(ConeNullability.NULLABLE, session.typeContext)
|
||||
}
|
||||
val typeArgument = buildTypeProjectionWithVariance {
|
||||
typeRef = returnType
|
||||
|
||||
+1
-1
@@ -48,7 +48,7 @@ class FirWhenExhaustivenessTransformer(private val bodyResolveComponents: BodyRe
|
||||
?: return null
|
||||
|
||||
// TODO: add some report logic about flexible type (see WHEN_ENUM_CAN_BE_NULL_IN_JAVA diagnostic in old frontend)
|
||||
val type = typeRef.coneTypeSafe<ConeKotlinType>()?.lowerBoundIfFlexible() ?: return null
|
||||
val type = typeRef.coneType.lowerBoundIfFlexible()
|
||||
val lookupTag = (type as? ConeLookupTagBasedType)?.lookupTag ?: return null
|
||||
val nullable = type.nullability == ConeNullability.NULLABLE
|
||||
val isExhaustive = when {
|
||||
|
||||
+4
-4
@@ -113,8 +113,8 @@ class IntegerLiteralTypeApproximationTransformer(
|
||||
val expectedType: ConeKotlinType? = when {
|
||||
!leftIsIlt && !rightIsIlt -> return operatorCall.compose()
|
||||
leftIsIlt && rightIsIlt -> null
|
||||
leftIsIlt -> rightArgument.typeRef.coneTypeUnsafe()
|
||||
rightIsIlt -> leftArgument.typeRef.coneTypeUnsafe()
|
||||
leftIsIlt -> rightArgument.typeRef.coneType
|
||||
rightIsIlt -> leftArgument.typeRef.coneType
|
||||
else -> throw IllegalStateException()
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ class IntegerOperatorsTypeUpdater(private val approximator: IntegerLiteralTypeAp
|
||||
val function: FirCallableDeclaration<*> = functionCall.getOriginalFunction() ?: return functionCall.compose()
|
||||
|
||||
if (function !is FirIntegerOperator) {
|
||||
val expectedType = function.receiverTypeRef?.coneTypeSafe<ConeKotlinType>()
|
||||
val expectedType = function.receiverTypeRef?.coneType
|
||||
return functionCall.transformExplicitReceiver(approximator, expectedType).compose()
|
||||
}
|
||||
// TODO: maybe unsafe?
|
||||
@@ -176,7 +176,7 @@ class IntegerOperatorsTypeUpdater(private val approximator: IntegerLiteralTypeAp
|
||||
}
|
||||
else -> {
|
||||
// TODO: handle overflow
|
||||
when (val argumentType = functionCall.argument.typeRef.coneTypeUnsafe<ConeKotlinType>()) {
|
||||
when (val argumentType = functionCall.argument.typeRef.coneType) {
|
||||
is ConeIntegerLiteralType -> {
|
||||
val argumentValue = argumentType.value
|
||||
val divisionByZero = argumentValue == 0L
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ internal fun FirValueParameter.transformVarargTypeToArrayType() {
|
||||
}
|
||||
|
||||
internal fun FirTypedDeclaration.transformTypeToArrayType() {
|
||||
val returnType = returnTypeRef.coneTypeUnsafe<ConeKotlinType>()
|
||||
val returnType = returnTypeRef.coneType
|
||||
transformReturnTypeRef(
|
||||
StoreType,
|
||||
returnTypeRef.withReplacedConeType(
|
||||
|
||||
+7
-7
@@ -158,7 +158,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
val typeRef = propertyReferenceAccess.typeRef
|
||||
if (typeRef is FirResolvedTypeRef && property.returnTypeRef is FirResolvedTypeRef) {
|
||||
val typeArguments = (typeRef.type as ConeClassLikeType).typeArguments
|
||||
val extensionType = property.receiverTypeRef?.coneTypeSafe<ConeKotlinType>()
|
||||
val extensionType = property.receiverTypeRef?.coneType
|
||||
val dispatchType = containingClass?.let { containingClass ->
|
||||
containingClass.symbol.constructStarProjectedType(containingClass.typeParameters.size)
|
||||
}
|
||||
@@ -169,7 +169,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
type = (typeRef.type as ConeClassLikeType).lookupTag.constructClassType(
|
||||
typeArguments.mapIndexed { index, argument ->
|
||||
when (index) {
|
||||
typeArguments.lastIndex -> property.returnTypeRef.coneTypeUnsafe()
|
||||
typeArguments.lastIndex -> property.returnTypeRef.coneType
|
||||
0 -> extensionType ?: dispatchType
|
||||
else -> dispatchType
|
||||
} ?: argument
|
||||
@@ -312,7 +312,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
|
||||
val receiverTypeRef = owner.receiverTypeRef
|
||||
if (receiverTypeRef != null) {
|
||||
withLabelAndReceiverType(owner.name, owner, receiverTypeRef.coneTypeUnsafe()) {
|
||||
withLabelAndReceiverType(owner.name, owner, receiverTypeRef.coneType) {
|
||||
transformFunctionWithGivenSignature(accessor, resolutionMode)
|
||||
}
|
||||
} else {
|
||||
@@ -459,7 +459,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
withFullBodyResolve {
|
||||
val receiverTypeRef = simpleFunction.receiverTypeRef
|
||||
if (receiverTypeRef != null) {
|
||||
withLabelAndReceiverType(simpleFunction.name, simpleFunction, receiverTypeRef.coneTypeUnsafe()) {
|
||||
withLabelAndReceiverType(simpleFunction.name, simpleFunction, receiverTypeRef.coneType) {
|
||||
transformFunctionWithGivenSignature(simpleFunction, ResolutionMode.ContextIndependent)
|
||||
}
|
||||
} else {
|
||||
@@ -549,7 +549,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
|
||||
dataFlowAnalyzer.enterValueParameter(valueParameter)
|
||||
val transformedValueParameter =
|
||||
valueParameter.transformInitializer(integerLiteralTypeApproximator, valueParameter.returnTypeRef.coneTypeSafe())
|
||||
valueParameter.transformInitializer(integerLiteralTypeApproximator, valueParameter.returnTypeRef.coneType)
|
||||
|
||||
val result = transformDeclarationContent(
|
||||
transformedValueParameter,
|
||||
@@ -641,7 +641,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
af = af.transformValueParameters(ImplicitToErrorTypeTransformer, null)
|
||||
val bodyExpectedType = returnTypeRefFromResolvedAtom ?: expectedTypeRef
|
||||
val labelName = af.label?.name?.let { Name.identifier(it) }
|
||||
withLabelAndReceiverType(labelName, af, af.receiverTypeRef?.coneTypeSafe()) {
|
||||
withLabelAndReceiverType(labelName, af, af.receiverTypeRef?.coneType) {
|
||||
af = transformFunction(af, withExpectedType(bodyExpectedType)).single as FirAnonymousFunction
|
||||
}
|
||||
// To separate function and separate commit
|
||||
@@ -655,7 +655,7 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
|
||||
)
|
||||
af.transformSingle(writer, expectedTypeRef.coneTypeSafe<ConeKotlinType>()?.toExpectedType())
|
||||
val returnTypes = dataFlowAnalyzer.returnExpressionsOfAnonymousFunction(af)
|
||||
.mapNotNull { (it as? FirExpression)?.resultType?.coneTypeUnsafe() }
|
||||
.mapNotNull { (it as? FirExpression)?.resultType?.coneType }
|
||||
af.replaceReturnTypeRef(
|
||||
af.returnTypeRef.resolvedTypeFromPrototype(
|
||||
inferenceComponents.ctx.commonSuperTypeOrNull(returnTypes) ?: session.builtinTypes.unitType.type
|
||||
|
||||
+3
-3
@@ -411,7 +411,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
FirOperation.SAFE_AS -> {
|
||||
resolved.resultType =
|
||||
conversionTypeRef.withReplacedConeType(
|
||||
conversionTypeRef.coneTypeUnsafe<ConeKotlinType>().withNullability(
|
||||
conversionTypeRef.coneType.withNullability(
|
||||
ConeNullability.NULLABLE, session.typeContext,
|
||||
),
|
||||
)
|
||||
@@ -550,7 +550,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
lhs.replaceTypeRef(buildResolvedTypeRef { type = typeRef })
|
||||
typeRef
|
||||
} else {
|
||||
lhs.resultType.coneTypeUnsafe()
|
||||
lhs.resultType.coneType
|
||||
}
|
||||
}
|
||||
is FirResolvedReifiedParameterReference -> {
|
||||
@@ -558,7 +558,7 @@ open class FirExpressionsResolveTransformer(transformer: FirBodyResolveTransform
|
||||
symbol.constructType(emptyArray(), isNullable = false)
|
||||
}
|
||||
else -> {
|
||||
lhs.resultType.coneTypeUnsafe<ConeKotlinType>()
|
||||
lhs.resultType.coneType
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+4
-5
@@ -13,8 +13,7 @@ import org.jetbrains.kotlin.fir.declarations.FirContractDescriptionOwner
|
||||
import org.jetbrains.kotlin.fir.declarations.FirValueParameter
|
||||
import org.jetbrains.kotlin.fir.expressions.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.visitors.FirDefaultVisitor
|
||||
|
||||
class ConeEffectExtractor(
|
||||
@@ -116,7 +115,7 @@ class ConeEffectExtractor(
|
||||
val symbol = qualifiedAccessExpression.toResolvedCallableSymbol() ?: return null
|
||||
val parameter = symbol.fir as? FirValueParameter ?: return null
|
||||
val index = valueParameters.indexOf(parameter).takeUnless { it < 0 } ?: return null
|
||||
val type = parameter.returnTypeRef.coneTypeUnsafe<ConeKotlinType>()
|
||||
val type = parameter.returnTypeRef.coneType
|
||||
|
||||
val name = parameter.name.asString()
|
||||
return toValueParameterReference(type, index, name)
|
||||
@@ -140,7 +139,7 @@ class ConeEffectExtractor(
|
||||
): ConeContractDescriptionElement? {
|
||||
val declaration = thisReceiverExpression.calleeReference.boundSymbol?.fir ?: return null
|
||||
return if (declaration == owner) {
|
||||
val type = thisReceiverExpression.typeRef.coneTypeSafe<ConeKotlinType>() ?: return null
|
||||
val type = thisReceiverExpression.typeRef.coneType
|
||||
toValueParameterReference(type, -1, "this")
|
||||
} else {
|
||||
null
|
||||
@@ -160,7 +159,7 @@ class ConeEffectExtractor(
|
||||
|
||||
override fun visitTypeOperatorCall(typeOperatorCall: FirTypeOperatorCall, data: Nothing?): ConeContractDescriptionElement? {
|
||||
val arg = typeOperatorCall.argument.accept(this, data) as? ConeValueParameterReference ?: return null
|
||||
val type = typeOperatorCall.conversionTypeRef.coneTypeSafe<ConeKotlinType>() ?: return null
|
||||
val type = typeOperatorCall.conversionTypeRef.coneType
|
||||
val isNegated = typeOperatorCall.operation == FirOperation.NOT_IS
|
||||
return ConeIsInstancePredicate(arg, type, isNegated)
|
||||
}
|
||||
|
||||
+3
-3
@@ -19,7 +19,7 @@ import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.diagnostics.ConeContractDescriptionError
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirBodyResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.resolve.transformers.body.resolve.FirDeclarationsResolveTransformer
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||
import org.jetbrains.kotlin.fir.types.coneType
|
||||
import org.jetbrains.kotlin.fir.visitors.CompositeTransformResult
|
||||
import org.jetbrains.kotlin.fir.visitors.compose
|
||||
import org.jetbrains.kotlin.fir.visitors.transformSingle
|
||||
@@ -59,7 +59,7 @@ class FirContractResolveTransformer(
|
||||
return withTypeParametersOf(simpleFunction) {
|
||||
val receiverTypeRef = simpleFunction.receiverTypeRef
|
||||
if (receiverTypeRef != null) {
|
||||
withLabelAndReceiverType(simpleFunction.name, simpleFunction, receiverTypeRef.coneTypeUnsafe()) {
|
||||
withLabelAndReceiverType(simpleFunction.name, simpleFunction, receiverTypeRef.coneType) {
|
||||
transformContractDescriptionOwner(simpleFunction)
|
||||
}
|
||||
} else {
|
||||
@@ -101,7 +101,7 @@ class FirContractResolveTransformer(
|
||||
}
|
||||
val receiverTypeRef = owner.receiverTypeRef
|
||||
return if (receiverTypeRef != null) {
|
||||
withLabelAndReceiverType(owner.name, propertyAccessor, receiverTypeRef.coneTypeUnsafe()) {
|
||||
withLabelAndReceiverType(owner.name, propertyAccessor, receiverTypeRef.coneType) {
|
||||
transformContractDescriptionOwner(propertyAccessor)
|
||||
}
|
||||
} else {
|
||||
|
||||
+6
-9
@@ -26,11 +26,8 @@ import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.symbols.CallableId
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.FirResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.FirTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.fir.types.builder.buildResolvedTypeRef
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeUnsafe
|
||||
import org.jetbrains.kotlin.fir.types.impl.ConeTypeParameterTypeImpl
|
||||
import org.jetbrains.kotlin.fir.withKind
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
@@ -125,7 +122,7 @@ class FirClassSubstitutionScope(
|
||||
|
||||
val (newTypeParameters, newReceiverType, newReturnType, newSubstitutor) = createSubstitutedData(member)
|
||||
val newParameterTypes = member.valueParameters.map {
|
||||
it.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().substitute(newSubstitutor)
|
||||
it.returnTypeRef.coneType.substitute(newSubstitutor)
|
||||
}
|
||||
|
||||
if (newReceiverType == null && newReturnType == null && newParameterTypes.all { it == null } &&
|
||||
@@ -157,7 +154,7 @@ class FirClassSubstitutionScope(
|
||||
|
||||
val (newTypeParameters, _, newReturnType, newSubstitutor) = createSubstitutedData(constructor)
|
||||
val newParameterTypes = constructor.valueParameters.map {
|
||||
it.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().substitute(newSubstitutor)
|
||||
it.returnTypeRef.coneType.substitute(newSubstitutor)
|
||||
}
|
||||
|
||||
if (newReturnType == null && newParameterTypes.all { it == null } && newTypeParameters === constructor.typeParameters) {
|
||||
@@ -206,7 +203,7 @@ class FirClassSubstitutionScope(
|
||||
member as FirTypeParameterRefsOwner
|
||||
)
|
||||
|
||||
val receiverType = member.receiverTypeRef?.coneTypeUnsafe<ConeKotlinType>()
|
||||
val receiverType = member.receiverTypeRef?.coneType
|
||||
val newReceiverType = receiverType?.substitute(substitutor)
|
||||
|
||||
val returnType = typeCalculator.tryCalculateReturnType(member).type
|
||||
@@ -245,7 +242,7 @@ class FirClassSubstitutionScope(
|
||||
if (newTypeParameter == null) continue
|
||||
val original = oldTypeParameter as FirTypeParameter
|
||||
for (boundTypeRef in original.bounds) {
|
||||
val typeForBound = boundTypeRef.coneTypeUnsafe<ConeKotlinType>()
|
||||
val typeForBound = boundTypeRef.coneType
|
||||
val substitutedBound = typeForBound.substitute()
|
||||
newTypeParameter.bounds +=
|
||||
buildResolvedTypeRef {
|
||||
@@ -286,7 +283,7 @@ class FirClassSubstitutionScope(
|
||||
val newReturnType = returnType.substitute()
|
||||
|
||||
val newParameterTypes = member.getter.valueParameters.map {
|
||||
it.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().substitute()
|
||||
it.returnTypeRef.coneType.substitute()
|
||||
}
|
||||
|
||||
if (newReturnType == null && newParameterTypes.all { it == null }) {
|
||||
|
||||
+5
-5
@@ -47,7 +47,7 @@ class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideCheck
|
||||
}
|
||||
|
||||
override fun isEqualTypes(candidateTypeRef: FirTypeRef, baseTypeRef: FirTypeRef, substitutor: ConeSubstitutor) =
|
||||
isEqualTypes((candidateTypeRef as FirResolvedTypeRef).type, (baseTypeRef as FirResolvedTypeRef).type, substitutor)
|
||||
isEqualTypes(candidateTypeRef.coneType, baseTypeRef.coneType, substitutor)
|
||||
|
||||
|
||||
/**
|
||||
@@ -61,13 +61,13 @@ class FirStandardOverrideChecker(session: FirSession) : FirAbstractOverrideCheck
|
||||
baseTypeParameter: FirTypeParameter,
|
||||
substitutor: ConeSubstitutor
|
||||
): Boolean {
|
||||
val substitutedOverrideType = substitutor.substituteOrSelf(overrideBound.coneTypeUnsafe())
|
||||
val substitutedBaseType = substitutor.substituteOrSelf(baseBound.coneTypeUnsafe())
|
||||
val substitutedOverrideType = substitutor.substituteOrSelf(overrideBound.coneType)
|
||||
val substitutedBaseType = substitutor.substituteOrSelf(baseBound.coneType)
|
||||
|
||||
if (isEqualTypes(substitutedOverrideType, substitutedBaseType)) return true
|
||||
|
||||
return overrideTypeParameter.bounds.any { bound -> isEqualTypes(bound.coneTypeUnsafe(), substitutedBaseType, substitutor) } &&
|
||||
baseTypeParameter.bounds.any { bound -> isEqualTypes(bound.coneTypeUnsafe(), substitutedOverrideType, substitutor) }
|
||||
return overrideTypeParameter.bounds.any { bound -> isEqualTypes(bound.coneType, substitutedBaseType, substitutor) } &&
|
||||
baseTypeParameter.bounds.any { bound -> isEqualTypes(bound.coneType, substitutedOverrideType, substitutor) }
|
||||
}
|
||||
|
||||
private fun isCompatibleTypeParameters(
|
||||
|
||||
+2
-5
@@ -16,10 +16,7 @@ import org.jetbrains.kotlin.fir.scopes.FirScope
|
||||
import org.jetbrains.kotlin.fir.scopes.FirTypeScope
|
||||
import org.jetbrains.kotlin.fir.scopes.ProcessorAction
|
||||
import org.jetbrains.kotlin.fir.symbols.impl.*
|
||||
import org.jetbrains.kotlin.fir.types.ConeFlexibleType
|
||||
import org.jetbrains.kotlin.fir.types.ConeKotlinType
|
||||
import org.jetbrains.kotlin.fir.types.ConeTypeCheckerContext
|
||||
import org.jetbrains.kotlin.fir.types.coneTypeSafe
|
||||
import org.jetbrains.kotlin.fir.types.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.types.AbstractTypeChecker
|
||||
import org.jetbrains.kotlin.types.AbstractTypeCheckerContext
|
||||
@@ -142,7 +139,7 @@ class FirTypeIntersectionScope private constructor(
|
||||
if (aFir !is FirCallableMemberDeclaration<*> || bFir !is FirCallableMemberDeclaration<*>) return false
|
||||
|
||||
val substitutor = buildSubstitutorForOverridesCheck(aFir, bFir) ?: return false
|
||||
|
||||
// NB: these lines throw CCE in modularized tests when changed to just .coneType (FirImplicitTypeRef)
|
||||
val aReturnType = a.fir.returnTypeRef.coneTypeSafe<ConeKotlinType>()?.let(substitutor::substituteOrSelf) ?: return false
|
||||
val bReturnType = b.fir.returnTypeRef.coneTypeSafe<ConeKotlinType>() ?: return false
|
||||
|
||||
|
||||
@@ -228,7 +228,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
//require(this is ConeSymbol)
|
||||
return when (this) {
|
||||
is ConeTypeVariableTypeConstructor -> emptyList()
|
||||
is FirTypeParameterSymbol -> fir.bounds.map { it.coneTypeUnsafe() }
|
||||
is FirTypeParameterSymbol -> fir.bounds.map { it.coneType }
|
||||
is FirClassSymbol<*> -> fir.superConeTypes
|
||||
is FirTypeAliasSymbol -> listOfNotNull(fir.expandedConeType)
|
||||
is ConeCapturedTypeConstructor -> supertypes!!
|
||||
@@ -259,7 +259,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
|
||||
override fun TypeParameterMarker.getUpperBound(index: Int): KotlinTypeMarker {
|
||||
require(this is FirTypeParameterSymbol)
|
||||
return this.fir.bounds[index].coneTypeUnsafe()
|
||||
return this.fir.bounds[index].coneType
|
||||
}
|
||||
|
||||
override fun TypeParameterMarker.getTypeConstructor(): TypeConstructorMarker {
|
||||
@@ -477,7 +477,7 @@ interface ConeTypeContext : TypeSystemContext, TypeSystemOptimizationContext, Ty
|
||||
|
||||
override fun TypeParameterMarker.getRepresentativeUpperBound(): KotlinTypeMarker {
|
||||
require(this is FirTypeParameterSymbol)
|
||||
return this.fir.bounds.getOrNull(0)?.let { (it as? FirResolvedTypeRef)?.type }
|
||||
return this.fir.bounds.getOrNull(0)?.let { it.coneType }
|
||||
?: session.builtinTypes.nullableAnyType.type
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ fun ConeKotlinType.canHaveUndefinedNullability(): Boolean {
|
||||
|
||||
private fun ConeTypeParameterType.hasNotNullUpperBound(): Boolean {
|
||||
return lookupTag.typeParameterSymbol.fir.bounds.any {
|
||||
val boundType = it.coneTypeUnsafe<ConeKotlinType>()
|
||||
val boundType = it.coneType
|
||||
if (boundType is ConeTypeParameterType) {
|
||||
boundType.hasNotNullUpperBound()
|
||||
} else {
|
||||
@@ -195,7 +195,7 @@ internal fun FirTypeProjection.toConeTypeProjection(): ConeTypeProjection =
|
||||
when (this) {
|
||||
is FirStarProjection -> ConeStarProjection
|
||||
is FirTypeProjectionWithVariance -> {
|
||||
val type = (this.typeRef as FirResolvedTypeRef).type
|
||||
val type = typeRef.coneType
|
||||
type.toTypeProjection(this.variance)
|
||||
}
|
||||
else -> error("!")
|
||||
|
||||
@@ -21,6 +21,7 @@ inline fun <reified T : ConeKotlinType> FirTypeRef.coneTypeSafe(): T? {
|
||||
}
|
||||
return (this as? FirResolvedTypeRef)?.type as? T
|
||||
}
|
||||
inline val FirTypeRef.coneType: ConeKotlinType get() = coneTypeUnsafe()
|
||||
|
||||
val FirTypeRef.isAny: Boolean get() = isBuiltinType(StandardClassIds.Any, false)
|
||||
val FirTypeRef.isNullableAny: Boolean get() = isBuiltinType(StandardClassIds.Any, true)
|
||||
|
||||
+2
-2
@@ -75,12 +75,12 @@ class FirAnalysisSession(
|
||||
override fun getReturnTypeForKtDeclaration(declaration: KtDeclaration): TypeInfo {
|
||||
assertIsValid()
|
||||
val firDeclaration = declaration.getOrBuildFirOfType<FirCallableDeclaration<*>>()
|
||||
return firDeclaration.returnTypeRef.coneTypeUnsafe<ConeKotlinType>().asTypeInfo(declaration.session)
|
||||
return firDeclaration.returnTypeRef.coneType.asTypeInfo(declaration.session)
|
||||
}
|
||||
|
||||
override fun getKtExpressionType(expression: KtExpression): TypeInfo {
|
||||
assertIsValid()
|
||||
return expression.getOrBuildFirOfType<FirExpression>().typeRef.coneTypeUnsafe<ConeKotlinType>().asTypeInfo(expression.session)
|
||||
return expression.getOrBuildFirOfType<FirExpression>().typeRef.coneType.asTypeInfo(expression.session)
|
||||
}
|
||||
|
||||
override fun isSubclassOf(klass: KtClassOrObject, superClassId: ClassId): Boolean {
|
||||
|
||||
-2
@@ -7,8 +7,6 @@ package org.jetbrains.kotlin.fir.plugin
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.Visibilities
|
||||
import org.jetbrains.kotlin.descriptors.Visibility
|
||||
import org.jetbrains.kotlin.fir.FirEffectiveVisibility
|
||||
import org.jetbrains.kotlin.fir.FirEffectiveVisibilityImpl
|
||||
import org.jetbrains.kotlin.fir.FirSession
|
||||
import org.jetbrains.kotlin.fir.declarations.FirAnnotatedDeclaration
|
||||
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
|
||||
|
||||
Reference in New Issue
Block a user