From 82d52ef6fc7956ff74baeacadf412d5d845da976 Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 10 Jan 2024 21:01:30 +0100 Subject: [PATCH] [psi] add parenthesis around a nullable functional type text ^KT-64862 fixed --- .../org/jetbrains/kotlin/psi/KtTypeReference.kt | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/compiler/psi/src/org/jetbrains/kotlin/psi/KtTypeReference.kt b/compiler/psi/src/org/jetbrains/kotlin/psi/KtTypeReference.kt index 2236a982093..b68fb2c71c2 100644 --- a/compiler/psi/src/org/jetbrains/kotlin/psi/KtTypeReference.kt +++ b/compiler/psi/src/org/jetbrains/kotlin/psi/KtTypeReference.kt @@ -103,7 +103,20 @@ class KtTypeReference : KtModifierListOwnerStub getTypeText(typeElement.getLeftTypeRef()?.typeElement) + " & " + getTypeText(typeElement.getRightTypeRef()?.typeElement) - is KtNullableType -> getTypeText(typeElement.innerType) + "?" + is KtNullableType -> { + val innerType = typeElement.innerType + buildString { + val parenthesisRequired = innerType is KtFunctionType + if (parenthesisRequired) { + append("(") + } + append(getTypeText(innerType)) + append("?") + if (parenthesisRequired) { + append(")") + } + } + } null -> null else -> error("Unsupported type $typeElement") }