[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, receiverTypeText,
element as KtCallableDeclaration, element as KtCallableDeclaration,
changeInfo.method, changeInfo.method,
Variance.IN_VARIANCE Variance.IN_VARIANCE,
true
) else null ) else null
(element as KtCallableDeclaration).setReceiverTypeReference(receiverTypeRef)?.let { shortenReferences(it) } (element as KtCallableDeclaration).setReceiverTypeReference(receiverTypeRef)?.let { shortenReferences(it) }
} }

View File

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