[kotlin] k2: ensure intersection types receive parenthesis on receiver position

fix braces for top level functions

^KTIJ-28716 fixed

GitOrigin-RevId: cdbba08ef56516faf2f7e7884554998981231cd5
This commit is contained in:
Anna Kozlova
2024-02-06 10:35:42 +01:00
committed by intellij-monorepo-bot
parent 074d7fe8b3
commit b027de1e29
2 changed files with 11 additions and 11 deletions

View File

@@ -315,7 +315,8 @@ class KotlinChangeSignatureUsageProcessor : ChangeSignatureUsageProcessor {
receiverTypeText,
element as KtCallableDeclaration,
changeInfo.method,
Variance.IN_VARIANCE
Variance.IN_VARIANCE,
true
) else null
(element as KtCallableDeclaration).setReceiverTypeReference(receiverTypeRef)?.let { shortenReferences(it) }
}

View File

@@ -27,7 +27,8 @@ internal fun KtPsiFactory.createType(
typeText: String,
inheritedCallable: KtDeclaration?,
baseFunction: PsiElement,
variance: Variance
variance: Variance,
isReceiver: Boolean = false
): KtTypeReference {
if (inheritedCallable != null) {
allowAnalysisFromWriteAction {
@@ -52,16 +53,14 @@ internal fun KtPsiFactory.createType(
}
val ktSubstitutor = createSubstitutor(inheritedCallable, baseFunction)
if (ktSubstitutor != null) {
val ktType = createTypeCodeFragment(typeText, baseFunction).getContentElement()?.getKtType()
if (ktType != null) {
val type = ktSubstitutor.substitute(ktType)
val substitutedType = type.render(position = variance)
if (type is KtDefinitelyNotNullType) {
return createType("($substitutedType)")
}
return createType(substitutedType)
val ktType = createTypeCodeFragment(typeText, baseFunction).getContentElement()?.getKtType()
if (ktType != null) {
val type = ktSubstitutor?.substitute(ktType) ?: ktType
val substitutedType = type.render(position = variance)
if (isReceiver && type is KtDefinitelyNotNullType) {
return createType("($substitutedType)")
}
return createType(substitutedType)
}
}
}