diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt index b187c4e1542..ed3423d641c 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/FirUpperBoundViolatedHelpers.kt @@ -23,7 +23,6 @@ import org.jetbrains.kotlin.fir.types.* import org.jetbrains.kotlin.name.StandardClassIds import org.jetbrains.kotlin.types.AbstractTypeChecker import org.jetbrains.kotlin.types.TypeApproximatorConfiguration -import org.jetbrains.kotlin.types.Variance import kotlin.reflect.KClass /** @@ -57,11 +56,12 @@ fun checkUpperBoundViolated( val typeRefAndSourcesForArguments = extractArgumentsTypeRefAndSource(typeRef) ?: return val typeArgumentsWithSourceInfo = type.typeArguments.withIndex().map { (index, projection) -> val (argTypeRef, source) = - if (!isAbbreviatedType) + if (!isAbbreviatedType) { typeRefAndSourcesForArguments.getOrNull(index) ?: return - else + } else { // For abbreviated arguments we use the whole typeRef as a place to report FirTypeRefSource(null, typeRef.source) + } TypeArgumentWithSourceInfo(projection, argTypeRef, source) } @@ -86,8 +86,7 @@ private class FE10LikeConeSubstitutor( } val result = - projection.type!!.updateNullabilityIfNeeded(type) - ?.withCombinedAttributesFrom(type, useSiteSession.typeContext) + projection.type!!.updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type) ?: return null if (type.isUnsafeVarianceType(useSiteSession)) { @@ -103,7 +102,7 @@ private class FE10LikeConeSubstitutor( private fun ConeKotlinType.withProjection(projection: ConeTypeProjection): ConeKotlinType { 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? { diff --git a/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt b/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt index a63b5031c30..3b57e57861f 100644 --- a/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt +++ b/compiler/fir/fir2ir/jvm-backend/src/org/jetbrains/kotlin/fir/backend/jvm/FirJvmTypeMapper.kt @@ -246,10 +246,7 @@ class ConeTypeSystemCommonBackendContextForTypeMapping( require(it is ConeKotlinType) } @Suppress("UNCHECKED_CAST") - return defaultType().withArguments( - (arguments as List).toTypedArray(), - session.typeContext, - ) + return defaultType().withArguments((arguments as List).toTypedArray()) } override fun TypeParameterMarker.representativeUpperBound(): ConeKotlinType { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt index ffca10438ef..bc47b5bfd64 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/LookupTagUtils.kt @@ -76,7 +76,7 @@ fun FirSymbolProvider.getSymbolByLookupTag(lookupTag: ConeClassLikeLookupTag): F 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 // Existing @ParameterName annotation takes precedence if (attributes.customAnnotations.getAnnotationsByClassId(StandardNames.FqNames.parameterNameClassId).isNotEmpty()) return this @@ -100,16 +100,16 @@ fun ConeKotlinType.withParameterNameAnnotation(valueParameter: FirValueParameter } val attributesWithParameterNameAnnotation = ConeAttributes.create(listOf(CustomAnnotationTypeAttribute(listOf(parameterNameAnnotationCall)))) - return withCombinedAttributesFrom(attributesWithParameterNameAnnotation, context) + return withCombinedAttributesFrom(attributesWithParameterNameAnnotation) } -fun ConeKotlinType.withCombinedAttributesFrom(other: ConeKotlinType, context: ConeTypeContext): ConeKotlinType = - withCombinedAttributesFrom(other.attributes, context) +fun ConeKotlinType.withCombinedAttributesFrom(other: ConeKotlinType): ConeKotlinType = + withCombinedAttributesFrom(other.attributes) -private fun ConeKotlinType.withCombinedAttributesFrom(other: ConeAttributes, context: ConeTypeContext): ConeKotlinType { +private fun ConeKotlinType.withCombinedAttributesFrom(other: ConeAttributes): ConeKotlinType { if (other.isEmpty()) return this val combinedConeAttributes = attributes.add(other) - return withAttributes(combinedConeAttributes, context) + return withAttributes(combinedConeAttributes) } fun ConeKotlinType.findClassRepresentation( diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt index 8434fd83d14..0cfaf16da17 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/TypeExpansionUtils.kt @@ -77,7 +77,7 @@ fun ConeClassLikeType.directExpansionType( val resultType = expandedConeType(typeAlias) ?.applyNullabilityFrom(useSiteSession, this) - ?.applyAttributesFrom(useSiteSession, this) + ?.applyAttributesFrom(this) ?: return null if (resultType.typeArguments.isEmpty()) return resultType @@ -93,11 +93,10 @@ private fun ConeClassLikeType.applyNullabilityFrom( } private fun ConeClassLikeType.applyAttributesFrom( - session: FirSession, abbreviation: ConeClassLikeType ): ConeClassLikeType { val combinedAttributes = attributes.add(abbreviation.attributes) - return withAttributes(combinedAttributes, session.typeContext) + return withAttributes(combinedAttributes) } private fun mapTypeAliasArguments( @@ -135,7 +134,7 @@ private fun mapTypeAliasArguments( is ConeDefinitelyNotNullType, is ConeTypeParameterTypeImpl, is ConeFlexibleType -> { - mappedType.withAttributes(type.attributes.add(mappedType.attributes), useSiteSession.typeContext) + mappedType.withAttributes(type.attributes.add(mappedType.attributes)) } null -> return mappedProjection else -> mappedType diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt index 5aed2c60f60..93705c16854 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/resolve/substitution/Substitutors.kt @@ -105,7 +105,7 @@ abstract class AbstractConeSubstitutor(protected val typeContext: ConeTypeContex private fun ConeDefinitelyNotNullType.substituteOriginal(): ConeKotlinType? { val substituted = substituteOrNull(original) ?.withNullability(ConeNullability.NOT_NULL, typeContext) - ?.withAttributes(original.attributes, typeContext) + ?.withAttributes(original.attributes) ?: return null return ConeDefinitelyNotNullType.create(substituted, typeContext) ?: substituted } @@ -193,7 +193,7 @@ class ConeSubstitutorByMap( if (type !is ConeTypeParameterType) return null val result = substitution[type.lookupTag.symbol].updateNullabilityIfNeeded(type) - ?.withCombinedAttributesFrom(type, useSiteSession.typeContext) + ?.withCombinedAttributesFrom(type) ?: return null if (type.isUnsafeVarianceType(useSiteSession)) { return useSiteSession.typeApproximator.approximateToSuperType( @@ -223,7 +223,7 @@ fun createTypeSubstitutorByTypeConstructor(map: Map): SimpleTypeMarker { require(this is ConeKotlinType) - return this.withArguments(newArguments.cast>().toTypedArray(), this@ConeInferenceContext) + return this.withArguments(newArguments.cast>().toTypedArray()) } override fun SimpleTypeMarker.replaceArguments(replacement: (TypeArgumentMarker) -> TypeArgumentMarker): SimpleTypeMarker { require(this is ConeKotlinType) - return this.withArguments({ replacement(it).cast() }, this@ConeInferenceContext) + return this.withArguments { replacement(it) as ConeTypeProjection } } override fun KotlinTypeMarker.hasExactAnnotation(): Boolean { @@ -387,7 +387,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo override fun KotlinTypeMarker.removeExactAnnotation(): KotlinTypeMarker { require(this is ConeKotlinType) - return withAttributes(attributes.remove(CompilerConeAttributes.Exact), this@ConeInferenceContext) + return withAttributes(attributes.remove(CompilerConeAttributes.Exact)) } override fun TypeConstructorMarker.toErrorType(): SimpleTypeMarker { @@ -415,10 +415,7 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo @Suppress("UNCHECKED_CAST") val newCustomAttributes = (newAttributes as List>).filter { it.isCustomAttribute() } val attributesToKeep = this.attributes.filterNot { it.isCustomAttribute() } - return withAttributes( - ConeAttributes.create(newCustomAttributes + attributesToKeep), - this@ConeInferenceContext - ) + return withAttributes(ConeAttributes.create(newCustomAttributes + attributesToKeep)) } override fun TypeConstructorMarker.getApproximatedIntegerLiteralType(): KotlinTypeMarker { diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt index 48d3a3d1cd6..6144dd9c26c 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/TypeUtils.kt @@ -89,7 +89,7 @@ fun ConeKotlinType.makeConeTypeDefinitelyNotNullOrNotNull(typeContext: ConeTypeC return ConeDefinitelyNotNullType.create(this, typeContext) ?: this.withNullability(ConeNullability.NOT_NULL, typeContext) } -fun T.withArguments(arguments: Array, typeSystemContext: ConeTypeContext): T { +fun T.withArguments(arguments: Array): T { if (this.typeArguments === arguments) { return this } @@ -98,15 +98,15 @@ fun T.withArguments(arguments: Array this 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()}") } } -fun T.withArguments(replacement: (ConeTypeProjection) -> ConeTypeProjection, typeSystemContext: ConeTypeContext) = - withArguments(typeArguments.map(replacement).toTypedArray(), typeSystemContext) +fun T.withArguments(replacement: (ConeTypeProjection) -> ConeTypeProjection) = + withArguments(typeArguments.map(replacement).toTypedArray()) -fun T.withAttributes(attributes: ConeAttributes, typeSystemContext: ConeTypeContext): T { +fun T.withAttributes(attributes: ConeAttributes): T { if (this.attributes == attributes) { return this } @@ -115,16 +115,10 @@ fun T.withAttributes(attributes: ConeAttributes, typeSystem return when (this) { is ConeClassErrorType -> this 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 ConeRawType -> ConeRawType( - lowerBound.withAttributes(attributes, typeSystemContext), - upperBound.withAttributes(attributes, typeSystemContext) - ) - is ConeFlexibleType -> ConeFlexibleType( - lowerBound.withAttributes(attributes, typeSystemContext), - upperBound.withAttributes(attributes, typeSystemContext) - ) + is ConeRawType -> ConeRawType(lowerBound.withAttributes(attributes), upperBound.withAttributes(attributes)) + is ConeFlexibleType -> ConeFlexibleType(lowerBound.withAttributes(attributes), upperBound.withAttributes(attributes)) is ConeTypeVariableType -> ConeTypeVariableType(nullability, lookupTag, attributes) is ConeCapturedType -> ConeCapturedType( captureStatus, lowerType, nullability, constructor, attributes, isProjectionNotNull, @@ -252,7 +246,7 @@ fun FirTypeRef.isUnsafeVarianceType(session: FirSession): Boolean { fun FirTypeRef.hasEnhancedNullability(): Boolean = coneTypeSafe()?.hasEnhancedNullability == true -fun FirTypeRef.withoutEnhancedNullability(typeSystemContext: ConeTypeContext): FirTypeRef { +fun FirTypeRef.withoutEnhancedNullability(): FirTypeRef { require(this is FirResolvedTypeRef) if (!hasEnhancedNullability()) return this return buildResolvedTypeRef { @@ -261,7 +255,6 @@ fun FirTypeRef.withoutEnhancedNullability(typeSystemContext: ConeTypeContext): F ConeAttributes.create( this@withoutEnhancedNullability.type.attributes.filter { it != CompilerConeAttributes.EnhancedNullability } ), - typeSystemContext, ) annotations += this@withoutEnhancedNullability.annotations } @@ -323,14 +316,13 @@ fun FirTypeRef.approximated( fun FirTypeRef.approximatedIfNeededOrSelf( approximator: ConeTypeApproximator, containingCallableVisibility: Visibility?, - typeSystemContext: ConeTypeContext, isInlineFunction: Boolean = false, ): FirTypeRef { val approximated = if (containingCallableVisibility == Visibilities.Public || containingCallableVisibility == Visibilities.Protected) approximatedForPublicPosition(approximator) else this - return approximated.hideLocalTypeIfNeeded(containingCallableVisibility, isInlineFunction).withoutEnhancedNullability(typeSystemContext) + return approximated.hideLocalTypeIfNeeded(containingCallableVisibility, isInlineFunction).withoutEnhancedNullability() } 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 return if (type is ConeFlexibleType) { ConeFlexibleType( - type.lowerBound.withArguments(capturedArguments, this), - type.upperBound.withArguments(capturedArguments, this), + type.lowerBound.withArguments(capturedArguments), + type.upperBound.withArguments(capturedArguments), ) } else { - type.withArguments(capturedArguments, this) + type.withArguments(capturedArguments) } } @@ -466,7 +458,7 @@ fun ConeTypeContext.captureArguments(type: ConeKotlinType, status: CaptureStatus return newArguments } -fun ConeTypeContext.captureFromExpressionInternal(type: ConeKotlinType): ConeKotlinType? { +internal fun ConeTypeContext.captureFromExpressionInternal(type: ConeKotlinType): ConeKotlinType? { if (type !is ConeIntersectionType && type !is ConeFlexibleType) { return captureFromArgumentsInternal(type, CaptureStatus.FROM_EXPRESSION) } @@ -491,12 +483,12 @@ fun ConeTypeContext.captureFromExpressionInternal(type: ConeKotlinType): ConeKot typeToReplace.intersectedTypes.map { componentType -> val capturedArguments = findCorrespondingCapturedArgumentsForType(componentType) ?: return@map componentType - componentType.withArguments(capturedArguments, this) + componentType.withArguments(capturedArguments) } } else { val capturedArguments = findCorrespondingCapturedArgumentsForType(typeToReplace) ?: return listOf(typeToReplace) - listOf(typeToReplace.withArguments(capturedArguments, this)) + listOf(typeToReplace.withArguments(capturedArguments)) } } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt index 3ccde0084d5..82e5fd1d02d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/providers/impl/FirTypeResolverImpl.kt @@ -441,7 +441,7 @@ class FirTypeResolverImpl(private val session: FirSession) : FirTypeResolver() { private fun createFunctionalType(typeRef: FirFunctionTypeRef): ConeClassLikeType { val parameters = 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) val classId = if (typeRef.isSuspend) { StandardClassIds.SuspendFunctionN(typeRef.parametersCount) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt index 0473a2b5e0b..6120f107653 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirCallCompletionResultsWriterTransformer.kt @@ -344,7 +344,7 @@ class FirCallCompletionResultsWriterTransformer( private fun ConeKotlinType.removeExactAttribute(): ConeKotlinType { if (attributes.contains(CompilerConeAttributes.Exact)) { - return withAttributes(attributes.remove(CompilerConeAttributes.Exact), session.typeContext) + return withAttributes(attributes.remove(CompilerConeAttributes.Exact)) } return this @@ -910,7 +910,7 @@ internal class FirDeclarationCompletionResultsWriter( typeRef.resolvedTypeFromPrototype(it) } ?: typeRef if (data is ApproximationData.ApproximateByStatus) { - return result.approximatedIfNeededOrSelf(typeApproximator, data.visibility, typeContext, data.isInline) + return result.approximatedIfNeededOrSelf(typeApproximator, data.visibility, data.isInline) } return result } diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt index 081b86e3e00..fb4c6ba76b7 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/FirSyntheticCallGenerator.kt @@ -319,7 +319,6 @@ class FirSyntheticCallGenerator( val returnType = rightArgumentType.resolvedTypeFromPrototype( rightArgumentType.type.withAttributes( ConeAttributes.create(listOf(CompilerConeAttributes.Exact)), - session.typeContext, ) ) diff --git a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt index 248a38940d5..68066198c0d 100644 --- a/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt +++ b/compiler/fir/resolve/src/org/jetbrains/kotlin/fir/resolve/transformers/body/resolve/FirDeclarationsResolveTransformer.kt @@ -627,7 +627,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor returnExpression.resultType.approximatedIfNeededOrSelf( session.typeApproximator, simpleFunction?.visibilityForApproximation(), - transformer.session.typeContext, simpleFunction?.isInline == true ) ) @@ -989,7 +988,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor expectedType.approximatedIfNeededOrSelf( session.typeApproximator, backingField.visibilityForApproximation(), - session.typeContext, ) ) ) @@ -1014,7 +1012,6 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor expectedType.approximatedIfNeededOrSelf( session.typeApproximator, variable.visibilityForApproximation(), - session.typeContext, ) ) )