FIR: drop some usages of ConeTypeContext

This commit is contained in:
Mikhail Glukhikh
2021-12-13 18:42:16 +03:00
committed by TeamCityServer
parent 81ff9b820a
commit d1194e5fd2
11 changed files with 44 additions and 64 deletions
@@ -23,7 +23,6 @@ import org.jetbrains.kotlin.fir.types.*
import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.name.StandardClassIds
import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.AbstractTypeChecker
import org.jetbrains.kotlin.types.TypeApproximatorConfiguration import org.jetbrains.kotlin.types.TypeApproximatorConfiguration
import org.jetbrains.kotlin.types.Variance
import kotlin.reflect.KClass import kotlin.reflect.KClass
/** /**
@@ -57,11 +56,12 @@ fun checkUpperBoundViolated(
val typeRefAndSourcesForArguments = extractArgumentsTypeRefAndSource(typeRef) ?: return val typeRefAndSourcesForArguments = extractArgumentsTypeRefAndSource(typeRef) ?: return
val typeArgumentsWithSourceInfo = type.typeArguments.withIndex().map { (index, projection) -> val typeArgumentsWithSourceInfo = type.typeArguments.withIndex().map { (index, projection) ->
val (argTypeRef, source) = val (argTypeRef, source) =
if (!isAbbreviatedType) if (!isAbbreviatedType) {
typeRefAndSourcesForArguments.getOrNull(index) ?: return typeRefAndSourcesForArguments.getOrNull(index) ?: return
else } else {
// For abbreviated arguments we use the whole typeRef as a place to report // For abbreviated arguments we use the whole typeRef as a place to report
FirTypeRefSource(null, typeRef.source) FirTypeRefSource(null, typeRef.source)
}
TypeArgumentWithSourceInfo(projection, argTypeRef, source) TypeArgumentWithSourceInfo(projection, argTypeRef, source)
} }
@@ -86,8 +86,7 @@ private class FE10LikeConeSubstitutor(
} }
val result = val result =
projection.type!!.updateNullabilityIfNeeded(type) projection.type!!.updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type)
?.withCombinedAttributesFrom(type, useSiteSession.typeContext)
?: return null ?: return null
if (type.isUnsafeVarianceType(useSiteSession)) { if (type.isUnsafeVarianceType(useSiteSession)) {
@@ -103,7 +102,7 @@ private class FE10LikeConeSubstitutor(
private fun ConeKotlinType.withProjection(projection: ConeTypeProjection): ConeKotlinType { private fun ConeKotlinType.withProjection(projection: ConeTypeProjection): ConeKotlinType {
if (projection.kind == ProjectionKind.INVARIANT) return this if (projection.kind == ProjectionKind.INVARIANT) return this
return withAttributes(ConeAttributes.create(listOf(OriginalProjectionTypeAttribute(projection))), useSiteSession.typeContext) return withAttributes(ConeAttributes.create(listOf(OriginalProjectionTypeAttribute(projection))))
} }
override fun substituteArgument(projection: ConeTypeProjection, lookupTag: ConeClassLikeLookupTag, index: Int): ConeTypeProjection? { override fun substituteArgument(projection: ConeTypeProjection, lookupTag: ConeClassLikeLookupTag, index: Int): ConeTypeProjection? {
@@ -246,10 +246,7 @@ class ConeTypeSystemCommonBackendContextForTypeMapping(
require(it is ConeKotlinType) require(it is ConeKotlinType)
} }
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
return defaultType().withArguments( return defaultType().withArguments((arguments as List<ConeKotlinType>).toTypedArray())
(arguments as List<ConeKotlinType>).toTypedArray(),
session.typeContext,
)
} }
override fun TypeParameterMarker.representativeUpperBound(): ConeKotlinType { override fun TypeParameterMarker.representativeUpperBound(): ConeKotlinType {
@@ -76,7 +76,7 @@ fun FirSymbolProvider.getSymbolByLookupTag(lookupTag: ConeClassLikeLookupTag): F
return lookupTag.toSymbol(session) return lookupTag.toSymbol(session)
} }
fun ConeKotlinType.withParameterNameAnnotation(valueParameter: FirValueParameter, context: ConeTypeContext): ConeKotlinType { fun ConeKotlinType.withParameterNameAnnotation(valueParameter: FirValueParameter): ConeKotlinType {
if (valueParameter.name == SpecialNames.NO_NAME_PROVIDED || valueParameter.name == SpecialNames.UNDERSCORE_FOR_UNUSED_VAR) return this if (valueParameter.name == SpecialNames.NO_NAME_PROVIDED || valueParameter.name == SpecialNames.UNDERSCORE_FOR_UNUSED_VAR) return this
// Existing @ParameterName annotation takes precedence // Existing @ParameterName annotation takes precedence
if (attributes.customAnnotations.getAnnotationsByClassId(StandardNames.FqNames.parameterNameClassId).isNotEmpty()) return this if (attributes.customAnnotations.getAnnotationsByClassId(StandardNames.FqNames.parameterNameClassId).isNotEmpty()) return this
@@ -100,16 +100,16 @@ fun ConeKotlinType.withParameterNameAnnotation(valueParameter: FirValueParameter
} }
val attributesWithParameterNameAnnotation = val attributesWithParameterNameAnnotation =
ConeAttributes.create(listOf(CustomAnnotationTypeAttribute(listOf(parameterNameAnnotationCall)))) ConeAttributes.create(listOf(CustomAnnotationTypeAttribute(listOf(parameterNameAnnotationCall))))
return withCombinedAttributesFrom(attributesWithParameterNameAnnotation, context) return withCombinedAttributesFrom(attributesWithParameterNameAnnotation)
} }
fun ConeKotlinType.withCombinedAttributesFrom(other: ConeKotlinType, context: ConeTypeContext): ConeKotlinType = fun ConeKotlinType.withCombinedAttributesFrom(other: ConeKotlinType): ConeKotlinType =
withCombinedAttributesFrom(other.attributes, context) withCombinedAttributesFrom(other.attributes)
private fun ConeKotlinType.withCombinedAttributesFrom(other: ConeAttributes, context: ConeTypeContext): ConeKotlinType { private fun ConeKotlinType.withCombinedAttributesFrom(other: ConeAttributes): ConeKotlinType {
if (other.isEmpty()) return this if (other.isEmpty()) return this
val combinedConeAttributes = attributes.add(other) val combinedConeAttributes = attributes.add(other)
return withAttributes(combinedConeAttributes, context) return withAttributes(combinedConeAttributes)
} }
fun ConeKotlinType.findClassRepresentation( fun ConeKotlinType.findClassRepresentation(
@@ -77,7 +77,7 @@ fun ConeClassLikeType.directExpansionType(
val resultType = expandedConeType(typeAlias) val resultType = expandedConeType(typeAlias)
?.applyNullabilityFrom(useSiteSession, this) ?.applyNullabilityFrom(useSiteSession, this)
?.applyAttributesFrom(useSiteSession, this) ?.applyAttributesFrom(this)
?: return null ?: return null
if (resultType.typeArguments.isEmpty()) return resultType if (resultType.typeArguments.isEmpty()) return resultType
@@ -93,11 +93,10 @@ private fun ConeClassLikeType.applyNullabilityFrom(
} }
private fun ConeClassLikeType.applyAttributesFrom( private fun ConeClassLikeType.applyAttributesFrom(
session: FirSession,
abbreviation: ConeClassLikeType abbreviation: ConeClassLikeType
): ConeClassLikeType { ): ConeClassLikeType {
val combinedAttributes = attributes.add(abbreviation.attributes) val combinedAttributes = attributes.add(abbreviation.attributes)
return withAttributes(combinedAttributes, session.typeContext) return withAttributes(combinedAttributes)
} }
private fun mapTypeAliasArguments( private fun mapTypeAliasArguments(
@@ -135,7 +134,7 @@ private fun mapTypeAliasArguments(
is ConeDefinitelyNotNullType, is ConeDefinitelyNotNullType,
is ConeTypeParameterTypeImpl, is ConeTypeParameterTypeImpl,
is ConeFlexibleType -> { is ConeFlexibleType -> {
mappedType.withAttributes(type.attributes.add(mappedType.attributes), useSiteSession.typeContext) mappedType.withAttributes(type.attributes.add(mappedType.attributes))
} }
null -> return mappedProjection null -> return mappedProjection
else -> mappedType else -> mappedType
@@ -105,7 +105,7 @@ abstract class AbstractConeSubstitutor(protected val typeContext: ConeTypeContex
private fun ConeDefinitelyNotNullType.substituteOriginal(): ConeKotlinType? { private fun ConeDefinitelyNotNullType.substituteOriginal(): ConeKotlinType? {
val substituted = substituteOrNull(original) val substituted = substituteOrNull(original)
?.withNullability(ConeNullability.NOT_NULL, typeContext) ?.withNullability(ConeNullability.NOT_NULL, typeContext)
?.withAttributes(original.attributes, typeContext) ?.withAttributes(original.attributes)
?: return null ?: return null
return ConeDefinitelyNotNullType.create(substituted, typeContext) ?: substituted return ConeDefinitelyNotNullType.create(substituted, typeContext) ?: substituted
} }
@@ -193,7 +193,7 @@ class ConeSubstitutorByMap(
if (type !is ConeTypeParameterType) return null if (type !is ConeTypeParameterType) return null
val result = val result =
substitution[type.lookupTag.symbol].updateNullabilityIfNeeded(type) substitution[type.lookupTag.symbol].updateNullabilityIfNeeded(type)
?.withCombinedAttributesFrom(type, useSiteSession.typeContext) ?.withCombinedAttributesFrom(type)
?: return null ?: return null
if (type.isUnsafeVarianceType(useSiteSession)) { if (type.isUnsafeVarianceType(useSiteSession)) {
return useSiteSession.typeApproximator.approximateToSuperType( return useSiteSession.typeApproximator.approximateToSuperType(
@@ -223,7 +223,7 @@ fun createTypeSubstitutorByTypeConstructor(map: Map<TypeConstructorMarker, ConeK
override fun substituteType(type: ConeKotlinType): ConeKotlinType? { override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null
val new = map[type.typeConstructor(context)] ?: return null val new = map[type.typeConstructor(context)] ?: return null
return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type, context) return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type)
} }
} }
} }
@@ -235,7 +235,7 @@ internal class TypeSubstitutorByTypeConstructor(
override fun substituteType(type: ConeKotlinType): ConeKotlinType? { override fun substituteType(type: ConeKotlinType): ConeKotlinType? {
if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null
val new = map[type.typeConstructor(typeContext)] ?: return null val new = map[type.typeConstructor(typeContext)] ?: return null
return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type, typeContext) return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type)
} }
} }
@@ -274,17 +274,17 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker { override fun KotlinTypeMarker.removeAnnotations(): KotlinTypeMarker {
require(this is ConeKotlinType) require(this is ConeKotlinType)
return withAttributes(ConeAttributes.Empty, this@ConeInferenceContext) return withAttributes(ConeAttributes.Empty)
} }
override fun SimpleTypeMarker.replaceArguments(newArguments: List<TypeArgumentMarker>): SimpleTypeMarker { override fun SimpleTypeMarker.replaceArguments(newArguments: List<TypeArgumentMarker>): SimpleTypeMarker {
require(this is ConeKotlinType) require(this is ConeKotlinType)
return this.withArguments(newArguments.cast<List<ConeTypeProjection>>().toTypedArray(), this@ConeInferenceContext) return this.withArguments(newArguments.cast<List<ConeTypeProjection>>().toTypedArray())
} }
override fun SimpleTypeMarker.replaceArguments(replacement: (TypeArgumentMarker) -> TypeArgumentMarker): SimpleTypeMarker { override fun SimpleTypeMarker.replaceArguments(replacement: (TypeArgumentMarker) -> TypeArgumentMarker): SimpleTypeMarker {
require(this is ConeKotlinType) require(this is ConeKotlinType)
return this.withArguments({ replacement(it).cast() }, this@ConeInferenceContext) return this.withArguments { replacement(it) as ConeTypeProjection }
} }
override fun KotlinTypeMarker.hasExactAnnotation(): Boolean { override fun KotlinTypeMarker.hasExactAnnotation(): Boolean {
@@ -387,7 +387,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
override fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker { override fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker {
require(this is ConeKotlinType) require(this is ConeKotlinType)
return withAttributes(attributes.remove(CompilerConeAttributes.Exact), this@ConeInferenceContext) return withAttributes(attributes.remove(CompilerConeAttributes.Exact))
} }
override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker { override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker {
@@ -415,10 +415,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo
@Suppress("UNCHECKED_CAST") @Suppress("UNCHECKED_CAST")
val newCustomAttributes = (newAttributes as List<ConeAttribute<*>>).filter { it.isCustomAttribute() } val newCustomAttributes = (newAttributes as List<ConeAttribute<*>>).filter { it.isCustomAttribute() }
val attributesToKeep = this.attributes.filterNot { it.isCustomAttribute() } val attributesToKeep = this.attributes.filterNot { it.isCustomAttribute() }
return withAttributes( return withAttributes(ConeAttributes.create(newCustomAttributes + attributesToKeep))
ConeAttributes.create(newCustomAttributes + attributesToKeep),
this@ConeInferenceContext
)
} }
override fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker { override fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker {
@@ -89,7 +89,7 @@ fun ConeKotlinType.makeConeTypeDefinitelyNotNullOrNotNull(typeContext: ConeTypeC
return ConeDefinitelyNotNullType.create(this, typeContext) ?: this.withNullability(ConeNullability.NOT_NULL, typeContext) return ConeDefinitelyNotNullType.create(this, typeContext) ?: this.withNullability(ConeNullability.NOT_NULL, typeContext)
} }
fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection>, typeSystemContext: ConeTypeContext): T { fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection>): T {
if (this.typeArguments === arguments) { if (this.typeArguments === arguments) {
return this return this
} }
@@ -98,15 +98,15 @@ fun <T : ConeKotlinType> T.withArguments(arguments: Array<out ConeTypeProjection
return when (this) { return when (this) {
is ConeClassErrorType -> this is ConeClassErrorType -> this
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, arguments, nullability.isNullable) as T is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, arguments, nullability.isNullable) as T
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withArguments(arguments, typeSystemContext)) as T is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withArguments(arguments)) as T
else -> error("Not supported: $this: ${this.render()}") else -> error("Not supported: $this: ${this.render()}")
} }
} }
fun <T : ConeKotlinType> T.withArguments(replacement: (ConeTypeProjection) -> ConeTypeProjection, typeSystemContext: ConeTypeContext) = fun <T : ConeKotlinType> T.withArguments(replacement: (ConeTypeProjection) -> ConeTypeProjection) =
withArguments(typeArguments.map(replacement).toTypedArray(), typeSystemContext) withArguments(typeArguments.map(replacement).toTypedArray())
fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes, typeSystemContext: ConeTypeContext): T { fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes): T {
if (this.attributes == attributes) { if (this.attributes == attributes) {
return this return this
} }
@@ -115,16 +115,10 @@ fun <T : ConeKotlinType> T.withAttributes(attributes: ConeAttributes, typeSystem
return when (this) { return when (this) {
is ConeClassErrorType -> this is ConeClassErrorType -> this
is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable, attributes) is ConeClassLikeTypeImpl -> ConeClassLikeTypeImpl(lookupTag, typeArguments, nullability.isNullable, attributes)
is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withAttributes(attributes, typeSystemContext)) is ConeDefinitelyNotNullType -> ConeDefinitelyNotNullType(original.withAttributes(attributes))
is ConeTypeParameterTypeImpl -> ConeTypeParameterTypeImpl(lookupTag, nullability.isNullable, attributes) is ConeTypeParameterTypeImpl -> ConeTypeParameterTypeImpl(lookupTag, nullability.isNullable, attributes)
is ConeRawType -> ConeRawType( is ConeRawType -> ConeRawType(lowerBound.withAttributes(attributes), upperBound.withAttributes(attributes))
lowerBound.withAttributes(attributes, typeSystemContext), is ConeFlexibleType -> ConeFlexibleType(lowerBound.withAttributes(attributes), upperBound.withAttributes(attributes))
upperBound.withAttributes(attributes, typeSystemContext)
)
is ConeFlexibleType -> ConeFlexibleType(
lowerBound.withAttributes(attributes, typeSystemContext),
upperBound.withAttributes(attributes, typeSystemContext)
)
is ConeTypeVariableType -> ConeTypeVariableType(nullability, lookupTag, attributes) is ConeTypeVariableType -> ConeTypeVariableType(nullability, lookupTag, attributes)
is ConeCapturedType -> ConeCapturedType( is ConeCapturedType -> ConeCapturedType(
captureStatus, lowerType, nullability, constructor, attributes, isProjectionNotNull, captureStatus, lowerType, nullability, constructor, attributes, isProjectionNotNull,
@@ -252,7 +246,7 @@ fun FirTypeRef.isUnsafeVarianceType(session: FirSession): Boolean {
fun FirTypeRef.hasEnhancedNullability(): Boolean = fun FirTypeRef.hasEnhancedNullability(): Boolean =
coneTypeSafe<ConeKotlinType>()?.hasEnhancedNullability == true coneTypeSafe<ConeKotlinType>()?.hasEnhancedNullability == true
fun FirTypeRef.withoutEnhancedNullability(typeSystemContext: ConeTypeContext): FirTypeRef { fun FirTypeRef.withoutEnhancedNullability(): FirTypeRef {
require(this is FirResolvedTypeRef) require(this is FirResolvedTypeRef)
if (!hasEnhancedNullability()) return this if (!hasEnhancedNullability()) return this
return buildResolvedTypeRef { return buildResolvedTypeRef {
@@ -261,7 +255,6 @@ fun FirTypeRef.withoutEnhancedNullability(typeSystemContext: ConeTypeContext): F
ConeAttributes.create( ConeAttributes.create(
this@withoutEnhancedNullability.type.attributes.filter { it != CompilerConeAttributes.EnhancedNullability } this@withoutEnhancedNullability.type.attributes.filter { it != CompilerConeAttributes.EnhancedNullability }
), ),
typeSystemContext,
) )
annotations += this@withoutEnhancedNullability.annotations annotations += this@withoutEnhancedNullability.annotations
} }
@@ -323,14 +316,13 @@ fun FirTypeRef.approximated(
fun FirTypeRef.approximatedIfNeededOrSelf( fun FirTypeRef.approximatedIfNeededOrSelf(
approximator: ConeTypeApproximator, approximator: ConeTypeApproximator,
containingCallableVisibility: Visibility?, containingCallableVisibility: Visibility?,
typeSystemContext: ConeTypeContext,
isInlineFunction: Boolean = false, isInlineFunction: Boolean = false,
): FirTypeRef { ): FirTypeRef {
val approximated = if (containingCallableVisibility == Visibilities.Public || containingCallableVisibility == Visibilities.Protected) val approximated = if (containingCallableVisibility == Visibilities.Public || containingCallableVisibility == Visibilities.Protected)
approximatedForPublicPosition(approximator) approximatedForPublicPosition(approximator)
else else
this this
return approximated.hideLocalTypeIfNeeded(containingCallableVisibility, isInlineFunction).withoutEnhancedNullability(typeSystemContext) return approximated.hideLocalTypeIfNeeded(containingCallableVisibility, isInlineFunction).withoutEnhancedNullability()
} }
fun FirTypeRef.approximatedForPublicPosition(approximator: ConeTypeApproximator): FirTypeRef = fun FirTypeRef.approximatedForPublicPosition(approximator: ConeTypeApproximator): FirTypeRef =
@@ -403,15 +395,15 @@ fun FirDeclaration.visibilityForApproximation(container: FirDeclaration?): Visib
} }
fun ConeTypeContext.captureFromArgumentsInternal(type: ConeKotlinType, status: CaptureStatus): ConeKotlinType? { internal fun ConeTypeContext.captureFromArgumentsInternal(type: ConeKotlinType, status: CaptureStatus): ConeKotlinType? {
val capturedArguments = captureArguments(type, status) ?: return null val capturedArguments = captureArguments(type, status) ?: return null
return if (type is ConeFlexibleType) { return if (type is ConeFlexibleType) {
ConeFlexibleType( ConeFlexibleType(
type.lowerBound.withArguments(capturedArguments, this), type.lowerBound.withArguments(capturedArguments),
type.upperBound.withArguments(capturedArguments, this), type.upperBound.withArguments(capturedArguments),
) )
} else { } else {
type.withArguments(capturedArguments, this) type.withArguments(capturedArguments)
} }
} }
@@ -466,7 +458,7 @@ fun ConeTypeContext.captureArguments(type: ConeKotlinType, status: CaptureStatus
return newArguments return newArguments
} }
fun ConeTypeContext.captureFromExpressionInternal(type: ConeKotlinType): ConeKotlinType? { internal fun ConeTypeContext.captureFromExpressionInternal(type: ConeKotlinType): ConeKotlinType? {
if (type !is ConeIntersectionType && type !is ConeFlexibleType) { if (type !is ConeIntersectionType && type !is ConeFlexibleType) {
return captureFromArgumentsInternal(type, CaptureStatus.FROM_EXPRESSION) return captureFromArgumentsInternal(type, CaptureStatus.FROM_EXPRESSION)
} }
@@ -491,12 +483,12 @@ fun ConeTypeContext.captureFromExpressionInternal(type: ConeKotlinType): ConeKot
typeToReplace.intersectedTypes.map { componentType -> typeToReplace.intersectedTypes.map { componentType ->
val capturedArguments = findCorrespondingCapturedArgumentsForType(componentType) val capturedArguments = findCorrespondingCapturedArgumentsForType(componentType)
?: return@map componentType ?: return@map componentType
componentType.withArguments(capturedArguments, this) componentType.withArguments(capturedArguments)
} }
} else { } else {
val capturedArguments = findCorrespondingCapturedArgumentsForType(typeToReplace) val capturedArguments = findCorrespondingCapturedArgumentsForType(typeToReplace)
?: return listOf(typeToReplace) ?: return listOf(typeToReplace)
listOf(typeToReplace.withArguments(capturedArguments, this)) listOf(typeToReplace.withArguments(capturedArguments))
} }
} }
@@ -441,7 +441,7 @@ 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?.coneType) + listOfNotNull(typeRef.receiverTypeRef?.coneType) +
typeRef.valueParameters.map { it.returnTypeRef.coneType.withParameterNameAnnotation(it, session.typeContext) } + typeRef.valueParameters.map { it.returnTypeRef.coneType.withParameterNameAnnotation(it) } +
listOf(typeRef.returnTypeRef.coneType) listOf(typeRef.returnTypeRef.coneType)
val classId = if (typeRef.isSuspend) { val classId = if (typeRef.isSuspend) {
StandardClassIds.SuspendFunctionN(typeRef.parametersCount) StandardClassIds.SuspendFunctionN(typeRef.parametersCount)
@@ -344,7 +344,7 @@ class FirCallCompletionResultsWriterTransformer(
private fun ConeKotlinType.removeExactAttribute(): ConeKotlinType { private fun ConeKotlinType.removeExactAttribute(): ConeKotlinType {
if (attributes.contains(CompilerConeAttributes.Exact)) { if (attributes.contains(CompilerConeAttributes.Exact)) {
return withAttributes(attributes.remove(CompilerConeAttributes.Exact), session.typeContext) return withAttributes(attributes.remove(CompilerConeAttributes.Exact))
} }
return this return this
@@ -910,7 +910,7 @@ internal class FirDeclarationCompletionResultsWriter(
typeRef.resolvedTypeFromPrototype(it) typeRef.resolvedTypeFromPrototype(it)
} ?: typeRef } ?: typeRef
if (data is ApproximationData.ApproximateByStatus) { if (data is ApproximationData.ApproximateByStatus) {
return result.approximatedIfNeededOrSelf(typeApproximator, data.visibility, typeContext, data.isInline) return result.approximatedIfNeededOrSelf(typeApproximator, data.visibility, data.isInline)
} }
return result return result
} }
@@ -319,7 +319,6 @@ class FirSyntheticCallGenerator(
val returnType = rightArgumentType.resolvedTypeFromPrototype( val returnType = rightArgumentType.resolvedTypeFromPrototype(
rightArgumentType.type.withAttributes( rightArgumentType.type.withAttributes(
ConeAttributes.create(listOf(CompilerConeAttributes.Exact)), ConeAttributes.create(listOf(CompilerConeAttributes.Exact)),
session.typeContext,
) )
) )
@@ -627,7 +627,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
returnExpression.resultType.approximatedIfNeededOrSelf( returnExpression.resultType.approximatedIfNeededOrSelf(
session.typeApproximator, session.typeApproximator,
simpleFunction?.visibilityForApproximation(), simpleFunction?.visibilityForApproximation(),
transformer.session.typeContext,
simpleFunction?.isInline == true simpleFunction?.isInline == true
) )
) )
@@ -989,7 +988,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
expectedType.approximatedIfNeededOrSelf( expectedType.approximatedIfNeededOrSelf(
session.typeApproximator, session.typeApproximator,
backingField.visibilityForApproximation(), backingField.visibilityForApproximation(),
session.typeContext,
) )
) )
) )
@@ -1014,7 +1012,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor
expectedType.approximatedIfNeededOrSelf( expectedType.approximatedIfNeededOrSelf(
session.typeApproximator, session.typeApproximator,
variable.visibilityForApproximation(), variable.visibilityForApproximation(),
session.typeContext,
) )
) )
) )