[FE] Fix contextual functional types rendering

This commit is contained in:
Anastasiya Shadrina
2021-09-12 23:49:50 +07:00
committed by TeamCityServer
parent 7fce2691e2
commit 369c86ebb0
4 changed files with 22 additions and 10 deletions
@@ -1,7 +1,7 @@
package
public fun test(): kotlin.Unit
public fun withAutoClose(/*0*/ block: @kotlin.ContextFunctionTypeParams(count = 1) () -> kotlin.Unit): kotlin.Unit
public fun withAutoClose(/*0*/ block: context(AutoCloseScope) () -> kotlin.Unit): kotlin.Unit
public fun File.open(): InputStream
public interface AutoCloseScope {
@@ -1,6 +1,6 @@
package
public fun handleClick(/*0*/ clickHandler: ClickHandler /* = @kotlin.ContextFunctionTypeParams(count = 1) (ClickEvent) -> kotlin.Unit */): kotlin.Unit
public fun handleClick(/*0*/ clickHandler: ClickHandler /* = context(Button) (ClickEvent) -> kotlin.Unit */): kotlin.Unit
public final class Button {
public constructor Button()
@@ -15,4 +15,4 @@ public final class ClickEvent {
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public typealias ClickHandler = @kotlin.ContextFunctionTypeParams(count = 1) (ClickEvent) -> kotlin.Unit
public typealias ClickHandler = context(Button) (ClickEvent) -> kotlin.Unit
@@ -1,10 +1,10 @@
package
public fun f2(/*0*/ g: @kotlin.ContextFunctionTypeParams(count = 1) (Param) -> kotlin.Unit): kotlin.Unit
public fun f4(/*0*/ g: @kotlin.ContextFunctionTypeParams(count = 1) () -> kotlin.Unit): kotlin.Unit
public fun f2(/*0*/ g: context(C) (Param) -> kotlin.Unit): kotlin.Unit
public fun f4(/*0*/ g: context(C) () -> kotlin.Unit): kotlin.Unit
public fun test(): kotlin.Unit
public fun R.f1(/*0*/ g: @kotlin.ContextFunctionTypeParams(count = 1) (R.(Param) -> kotlin.Unit)): kotlin.Unit
public fun R.f3(/*0*/ g: @kotlin.ContextFunctionTypeParams(count = 1) (R.() -> kotlin.Unit)): kotlin.Unit
public fun R.f1(/*0*/ g: context(C) R.(Param) -> kotlin.Unit): kotlin.Unit
public fun R.f3(/*0*/ g: context(C) R.() -> kotlin.Unit): kotlin.Unit
public final class C {
public constructor C()
@@ -36,7 +36,7 @@ internal class DescriptorRendererImpl(
private val functionTypeAnnotationsRenderer: DescriptorRendererImpl by lazy {
withOptions {
excludedTypeAnnotationClasses += listOf(StandardNames.FqNames.extensionFunctionType)
excludedTypeAnnotationClasses += listOf(StandardNames.FqNames.extensionFunctionType, StandardNames.FqNames.contextFunctionTypeParams)
} as DescriptorRendererImpl
}
@@ -317,15 +317,27 @@ internal class DescriptorRendererImpl(
private fun StringBuilder.renderFunctionType(type: KotlinType) {
val lengthBefore = length
// we need special renderer to skip @ExtensionFunctionType
// we need special renderer to skip @ExtensionFunctionType and @ContextFunctionTypeParams
with(functionTypeAnnotationsRenderer) {
renderAnnotations(type)
}
val hasAnnotations = length != lengthBefore
val receiverType = type.getReceiverTypeFromFunctionType()
val contextReceiversTypes = type.getContextReceiverTypesFromFunctionType()
if (contextReceiversTypes.isNotEmpty()) {
append("context(")
val withoutLast = contextReceiversTypes.subList(0, contextReceiversTypes.lastIndex)
for (contextReceiverType in withoutLast) {
renderNormalizedType(contextReceiverType)
append(", ")
}
renderNormalizedType(contextReceiversTypes.last())
append(") ")
}
val isSuspend = type.isSuspendFunctionType
val isNullable = type.isMarkedNullable
val receiverType = type.getReceiverTypeFromFunctionType()
val needParenthesis = isNullable || (hasAnnotations && receiverType != null)
if (needParenthesis) {