Render annotations in suspend functions in single modifier list (KT-20185)

#KT-20185 Fixed
This commit is contained in:
Nikolay Krasko
2017-09-13 12:57:19 +03:00
parent d20af1133a
commit b9872b7651
3 changed files with 45 additions and 8 deletions
@@ -16,6 +16,12 @@ typealias Test9 = suspend (() -> Unit) -> Unit
typealias Test10 = suspend (suspend () -> Unit) -> Unit
typealias Test11 = suspend () -> (suspend () -> Unit)
typealias Test12 = suspend (suspend (() -> Unit)) -> Unit
typealias Test13 = @A() suspend () -> Unit
typealias Test14 = @A suspend () -> Unit
typealias Test15 = (@A() suspend () -> Unit)?
typealias Test16 = (@A suspend () -> Unit)?
typealias Test17 = @A suspend RS.() -> Unit
typealias Test18 = (suspend () -> Unit)?
interface Supertype1 : <!SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE!>suspend () -> Unit<!> {
@@ -24,3 +30,8 @@ interface Supertype1 : <!SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE!>suspend () -> Unit<
interface Supertype2 : <!SUPERTYPE_IS_SUSPEND_FUNCTION_TYPE!>suspend String.() -> Unit<!> {
}
@Target(AnnotationTarget.TYPE)
annotation class A
interface RS
@@ -1,5 +1,18 @@
package
@kotlin.annotation.Target(allowedTargets = {AnnotationTarget.TYPE}) public final annotation class A : kotlin.Annotation {
public constructor A()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface RS {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public interface SAM {
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
@@ -25,6 +38,12 @@ public typealias Test1 = suspend () -> kotlin.Unit
public typealias Test10 = suspend (suspend () -> kotlin.Unit) -> kotlin.Unit
public typealias Test11 = suspend () -> suspend () -> kotlin.Unit
public typealias Test12 = suspend (suspend () -> kotlin.Unit) -> kotlin.Unit
public typealias Test13 = @A() suspend () -> kotlin.Unit
public typealias Test14 = @A() suspend () -> kotlin.Unit
public typealias Test15 = (@A() suspend () -> kotlin.Unit)?
public typealias Test16 = (@A() suspend () -> kotlin.Unit)?
public typealias Test17 = (@A() suspend RS.() -> kotlin.Unit)
public typealias Test18 = (suspend () -> kotlin.Unit)?
public typealias Test2 = suspend kotlin.Int.() -> kotlin.Unit
public typealias Test3 = () -> kotlin.Unit
public typealias Test4 = Action
@@ -309,22 +309,29 @@ internal class DescriptorRendererImpl(
}
val hasAnnotations = length != lengthBefore
val isSuspend = type.isSuspendFunctionType
val isNullable = type.isMarkedNullable
val receiverType = type.getReceiverTypeFromFunctionType()
val needParenthesis = isNullable || (hasAnnotations && receiverType != null)
if (needParenthesis) {
if (isSuspend) {
insert(lengthBefore, '(')
}
else {
if (hasAnnotations) {
assert(last() == ' ')
if (get(lastIndex - 1) != ')') {
// last annotation rendered without parenthesis - need to add them otherwise parsing will be incorrect
insert(lastIndex, "()")
}
}
if (needParenthesis && hasAnnotations) {
assert(last() == ' ')
if (get(lastIndex - 1) != ')') {
// last annotation rendered without parenthesis - need to add them otherwise parsing will be incorrect
insert(lastIndex, "()")
append("(")
}
}
if (needParenthesis) append("(")
renderModifier(this, type.isSuspendFunctionType, "suspend")
renderModifier(this, isSuspend, "suspend")
if (receiverType != null) {
val surroundReceiver = shouldRenderAsPrettyFunctionType(receiverType) && !receiverType.isMarkedNullable ||