diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/InlineClassesUtils.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/InlineClassesUtils.kt index bee9f65977e..05d4cc74732 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/InlineClassesUtils.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/declarations/InlineClassesUtils.kt @@ -20,7 +20,9 @@ import org.jetbrains.kotlin.types.model.typeConstructor internal fun ConeKotlinType.substitutedUnderlyingTypeForInlineClass(session: FirSession, context: ConeTypeContext): ConeKotlinType? { val unsubstitutedType = unsubstitutedUnderlyingTypeForInlineClass(session) ?: return null - val substitutor = createTypeSubstitutorByTypeConstructor(mapOf(this.typeConstructor(context) to this), context) + val substitutor = createTypeSubstitutorByTypeConstructor( + mapOf(this.typeConstructor(context) to this), context, approximateIntegerLiterals = true + ) return substitutor.substituteOrNull(unsubstitutedType) } 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 3e6382afe49..600b6767c03 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 @@ -217,13 +217,18 @@ class ConeSubstitutorByMap( override fun hashCode() = hashCode } -fun createTypeSubstitutorByTypeConstructor(map: Map, context: ConeTypeContext): ConeSubstitutor { +fun createTypeSubstitutorByTypeConstructor( + map: Map, + context: ConeTypeContext, + approximateIntegerLiterals: Boolean +): ConeSubstitutor { if (map.isEmpty()) return ConeSubstitutor.Empty return object : AbstractConeSubstitutor(context), TypeSubstitutorMarker { override fun substituteType(type: ConeKotlinType): ConeKotlinType? { if (type !is ConeLookupTagBasedType && type !is ConeStubType) return null val new = map[type.typeConstructor(context)] ?: return null - return new.approximateIntegerLiteralType().updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type) + val approximatedIntegerLiteralType = if (approximateIntegerLiterals) new.approximateIntegerLiteralType() else new + return approximatedIntegerLiteralType.updateNullabilityIfNeeded(type)?.withCombinedAttributesFrom(type) } } } diff --git a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt index 7ead263c8d3..5e7ce6aa32a 100644 --- a/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt +++ b/compiler/fir/providers/src/org/jetbrains/kotlin/fir/types/ConeInferenceContext.kt @@ -329,7 +329,9 @@ interface ConeInferenceContext : TypeSystemInferenceExtensionContext, ConeTypeCo override fun typeSubstitutorByTypeConstructor(map: Map): ConeSubstitutor { @Suppress("UNCHECKED_CAST") - return createTypeSubstitutorByTypeConstructor(map as Map, this) + return createTypeSubstitutorByTypeConstructor( + map as Map, this, approximateIntegerLiterals = false + ) } override fun createEmptySubstitutor(): ConeSubstitutor { 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 9b2eaab3b21..04746569afb 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 @@ -128,6 +128,7 @@ fun T.withAttributes(attributes: ConeAttributes): T { is ConeIntersectionType -> this // Attributes for stub types are not supported, and it's not obvious if it should is ConeStubType -> this + is ConeIntegerLiteralType -> this else -> error("Not supported: $this: ${this.render()}") } as T } 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 c705f9e5fc6..351a959bf08 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 @@ -453,7 +453,7 @@ class FirCallCompletionResultsWriterTransformer( private fun Candidate.createArgumentsMapping(): ExpectedArgumentType? { val lambdasReturnType = postponedAtoms.filterIsInstance().associate { - Pair(it.atom, finalSubstitutor.substituteOrSelf(substitutor.substituteOrSelf(it.returnType))) + Pair(it.atom, finalSubstitutor.substituteOrSelf(substitutor.substituteOrSelf(it.returnType)).approximateIntegerLiteralType()) } val isIntegerOperator = symbol.isWrappedIntegerOperator() 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 64f092cd58e..f2fcba58b7c 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 @@ -318,7 +318,9 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor } val typeVariableTypeToStubType = context.inferenceSession.createSyntheticStubTypes(system) - val substitutor = createTypeSubstitutorByTypeConstructor(typeVariableTypeToStubType, session.typeContext) + val substitutor = createTypeSubstitutorByTypeConstructor( + typeVariableTypeToStubType, session.typeContext, approximateIntegerLiterals = true + ) val delegateExpressionTypeRef = delegateExpression.typeRef val stubTypeSubstituted = substitutor.substituteOrNull(delegateExpressionTypeRef.coneType) delegateExpression.replaceTypeRef(delegateExpressionTypeRef.withReplacedConeType(stubTypeSubstituted)) @@ -338,7 +340,9 @@ open class FirDeclarationsResolveTransformer(transformer: FirBodyResolveTransfor system.markPostponedVariable(it.value.typeVariable) } val typeVariableTypeToStubType = context.inferenceSession.createSyntheticStubTypes(system) - val substitutor = createTypeSubstitutorByTypeConstructor(typeVariableTypeToStubType, session.typeContext) + val substitutor = createTypeSubstitutorByTypeConstructor( + typeVariableTypeToStubType, session.typeContext, approximateIntegerLiterals = true + ) val stubTypeSubstituted = substitutor.substituteOrSelf(provideDelegateCandidate.substitutor.substituteOrSelf(components.typeFromCallee(provideDelegateCall).type)) diff --git a/compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt b/compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt deleted file mode 100644 index 8478083f4cb..00000000000 --- a/compiler/testData/diagnostics/testsWithStdLib/greater.fir.kt +++ /dev/null @@ -1,12 +0,0 @@ -class Expression(val x: T) - -class GreaterOp(val expr1: Expression<*>, val expr2: Expression<*>) - -fun , S : T?> Expression.greater(other: T): GreaterOp = - GreaterOp(this, Expression(other)) - -fun foo(countExpr: Expression) { - countExpr.greater(0) - countExpr.greater("0") - countExpr.greater("0") -} diff --git a/compiler/testData/diagnostics/testsWithStdLib/greater.kt b/compiler/testData/diagnostics/testsWithStdLib/greater.kt index 16cc23c12b4..31625fc9ffd 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/greater.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/greater.kt @@ -1,3 +1,4 @@ +// FIR_IDENTICAL class Expression(val x: T) class GreaterOp(val expr1: Expression<*>, val expr2: Expression<*>)