Introduce 'SuspendFunction$n<...>' types.

This commit is contained in:
Dmitry Petrov
2016-12-14 13:45:34 +03:00
committed by Stanislav Erokhin
parent a15d423db4
commit 6e1340da82
8 changed files with 113 additions and 20 deletions
@@ -134,7 +134,7 @@ class TypeResolver(
val typeElement = typeReference.typeElement
val type = resolveTypeElement(c, annotations, typeElement)
val type = resolveTypeElement(c, annotations, typeReference.modifierList, typeElement)
c.trace.recordScope(c.scope, typeReference)
if (!type.isBare) {
@@ -175,8 +175,14 @@ class TypeResolver(
}
}
private fun resolveTypeElement(c: TypeResolutionContext, annotations: Annotations, typeElement: KtTypeElement?): PossiblyBareType {
private fun resolveTypeElement(c: TypeResolutionContext, annotations: Annotations, modifiers: KtModifierList?, typeElement: KtTypeElement?): PossiblyBareType {
var result: PossiblyBareType? = null
val hasSuspendModifier = modifiers?.hasModifier(KtTokens.SUSPEND_KEYWORD) ?: false
if (hasSuspendModifier && typeElement !is KtFunctionType) {
c.trace.report(Errors.WRONG_MODIFIER_TARGET.on(modifiers!!.getModifier(KtTokens.SUSPEND_KEYWORD)!!, KtTokens.SUSPEND_KEYWORD, "non-functional type"))
}
typeElement?.accept(object : KtVisitorVoid() {
override fun visitUserType(type: KtUserType) {
val qualifierResolutionResult = resolveDescriptorForType(c.scope, type, c.trace, c.isDebuggerContext)
@@ -198,7 +204,7 @@ class TypeResolver(
override fun visitNullableType(nullableType: KtNullableType) {
val innerType = nullableType.getInnerType()
val baseType = resolveTypeElement(c, annotations, innerType)
val baseType = resolveTypeElement(c, annotations, modifiers, innerType)
if (baseType.isNullable || innerType is KtNullableType || innerType is KtDynamicType) {
c.trace.report(REDUNDANT_NULLABLE.on(nullableType))
}
@@ -219,7 +225,8 @@ class TypeResolver(
moduleDescriptor.builtIns, annotations, receiverType,
parameterDescriptors.map { it.type },
parameterDescriptors.map { it.name },
returnType
returnType,
suspendFunction = hasSuspendModifier
))
}
@@ -0,0 +1,14 @@
typealias Action = () -> Unit
interface SAM {
fun run()
}
typealias Test1 = suspend () -> Unit
typealias Test2 = suspend Int.(String) -> Unit
typealias Test3 = <!WRONG_MODIFIER_TARGET!>suspend<!> Function0<Unit>
typealias Test4 = <!WRONG_MODIFIER_TARGET!>suspend<!> Action
typealias Test5 = List<suspend () -> Unit>
typealias Test6 = <!WRONG_MODIFIER_TARGET!>suspend<!> List<() -> Unit>
typealias Test7 = <!WRONG_MODIFIER_TARGET!>suspend<!> SAM
typealias Test8 = SuspendFunction0<Unit>
@@ -0,0 +1,17 @@
package
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
public abstract fun run(): kotlin.Unit
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
public typealias Action = () -> kotlin.Unit
public typealias Test1 = suspend () -> kotlin.Unit
public typealias Test2 = suspend kotlin.Int.(kotlin.String) -> kotlin.Unit
public typealias Test3 = () -> kotlin.Unit
public typealias Test4 = Action
public typealias Test5 = kotlin.collections.List<suspend () -> kotlin.Unit>
public typealias Test6 = kotlin.collections.List<() -> kotlin.Unit>
public typealias Test7 = SAM
public typealias Test8 = suspend () -> kotlin.Unit