Add custom applicability checks for suspend/coroutine modifiers

This commit is contained in:
Denis Zharkov
2016-05-26 19:00:53 +03:00
parent d760a2ec3b
commit b8d4d39f4d
22 changed files with 377 additions and 9 deletions
+34
View File
@@ -0,0 +1,34 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -NOTHING_TO_INLINE
class Controller
fun valid(<info descr="null">coroutine</info> <warning descr="[UNUSED_PARAMETER] Parameter 'c' is never used">c</warning>: Controller.() -> Continuation<Unit>) {
}
fun noFunctionType(<error descr="[INAPPLICABLE_MODIFIER] 'coroutine' modifier is inapplicable. The reason is that parameter should have function type with extension like 'Controller.() -> Continuation<Unit>'"><info descr="null">coroutine</info></error> <warning descr="[UNUSED_PARAMETER] Parameter 'c' is never used">c</warning>: Unit) {
}
fun noExtensionFunction(<error descr="[INAPPLICABLE_MODIFIER] 'coroutine' modifier is inapplicable. The reason is that parameter should have function type with extension like 'Controller.() -> Continuation<Unit>'"><info descr="null">coroutine</info></error> <warning descr="[UNUSED_PARAMETER] Parameter 'c' is never used">c</warning>: (Controller) -> Continuation<Unit>) {
}
fun nullableReturnType(<error descr="[INAPPLICABLE_MODIFIER] 'coroutine' modifier is inapplicable. The reason is that parameter should have function type like 'Controller.() -> Continuation<Unit>' (Continuation<Unit> for return type is necessary)"><info descr="null">coroutine</info></error> <warning descr="[UNUSED_PARAMETER] Parameter 'c' is never used">c</warning>: Controller.() -> Continuation<Unit>?) {
}
fun wrongReturnType(<error descr="[INAPPLICABLE_MODIFIER] 'coroutine' modifier is inapplicable. The reason is that parameter should have function type like 'Controller.() -> Continuation<Unit>' (Continuation<Unit> for return type is necessary)"><info descr="null">coroutine</info></error> <warning descr="[UNUSED_PARAMETER] Parameter 'c' is never used">c</warning>: Controller.() -> Collection<Unit>) {
}
fun notUnitContinuation(<error descr="[INAPPLICABLE_MODIFIER] 'coroutine' modifier is inapplicable. The reason is that parameter should have function type like 'Controller.() -> Continuation<Unit>' (Continuation<Unit> for return type is necessary)"><info descr="null">coroutine</info></error> <warning descr="[UNUSED_PARAMETER] Parameter 'c' is never used">c</warning>: Controller.() -> Continuation<Int>) {
}
<info descr="null">inline</info> fun inlineBuilder(<error descr="[INAPPLICABLE_MODIFIER] 'coroutine' modifier is inapplicable. The reason is that coroutine parameter of inline function should be marked as 'noinline'"><info descr="null">coroutine</info></error> <warning descr="[UNUSED_PARAMETER] Parameter 'c' is never used">c</warning>: Controller.() -> Continuation<Unit>) {
}
<warning descr="[NOTHING_TO_INLINE] Expected performance impact of inlining 'public inline fun inlineBuilderNoInlineCoroutine(noinline coroutine c: Controller.() -> Continuation<Unit>): Unit defined in root package' can be insignificant. Inlining works best for functions with lambda parameters"><info descr="null">inline</info></warning> fun inlineBuilderNoInline<TYPO descr="Typo: In word 'Coroutine'">Coroutine</TYPO>(<info descr="null">coroutine</info> <info descr="null">noinline</info> <warning descr="[UNUSED_PARAMETER] Parameter 'c' is never used">c</warning>: Controller.() -> Continuation<Unit>) {
}
+26
View File
@@ -0,0 +1,26 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -NOTHING_TO_INLINE
<error descr="[WRONG_MODIFIER_TARGET] Modifier 'suspend' is not applicable to 'top level function'"><info descr="null">suspend</info></error> fun notMember(<warning descr="[UNUSED_PARAMETER] Parameter 'x' is never used">x</warning>: Continuation<Int>) {
}
class Controller {
<info descr="null">suspend</info> fun valid(<warning descr="[UNUSED_PARAMETER] Parameter 'x' is never used">x</warning>: Continuation<Int>) {
}
<warning descr="[NOTHING_TO_INLINE] Expected performance impact of inlining 'public final inline suspend fun inlineFun(x: Continuation<Int>): Unit defined in Controller' can be insignificant. Inlining works best for functions with lambda parameters"><info descr="null">inline</info></warning> <error descr="[INAPPLICABLE_MODIFIER] 'suspend' modifier is inapplicable. The reason is that inline suspend functions are not supported"><info descr="null">suspend</info></error> fun inlineFun(<warning descr="[UNUSED_PARAMETER] Parameter 'x' is never used">x</warning>: Continuation<Int>) {
}
<error descr="[INAPPLICABLE_MODIFIER] 'suspend' modifier is inapplicable. The reason is that last parameter of suspend function should have a type of Continuation<T>"><info descr="null">suspend</info></error> fun noParams() {
}
<error descr="[INAPPLICABLE_MODIFIER] 'suspend' modifier is inapplicable. The reason is that last parameter of suspend function should have a type of Continuation<T>"><info descr="null">suspend</info></error> fun wrongParam(<warning descr="[UNUSED_PARAMETER] Parameter 'x' is never used">x</warning>: Collection<Int>) {
}
<info descr="null">suspend</info> fun starProjection(<warning descr="[UNUSED_PARAMETER] Parameter 'x' is never used">x</warning>: Continuation<*>) {
}
}