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") }