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