[FIR-TEST] Add coroutines diagnostic tests from old FE to FIR test suite

This commit is contained in:
Dmitriy Novozhilov
2020-06-22 17:36:23 +03:00
parent d0affc6c6a
commit 6a9504f26a
159 changed files with 4638 additions and 26 deletions
@@ -0,0 +1,7 @@
// !LANGUAGE: -AllowNullOperatorsForResult
// !DIAGNOSTICS: -UNUSED_EXPRESSION
fun test(r: Result<Int>?) {
r ?: 0
r?.isFailure
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +AllowNullOperatorsForResult
// !DIAGNOSTICS: -UNUSED_EXPRESSION
@@ -0,0 +1,9 @@
// !ALLOW_RESULT_RETURN_TYPE
// !LANGUAGE: -AllowNullOperatorsForResult
fun result(): Result<Int> = TODO()
val resultP: Result<Int> = result()
fun f(r1: Result<Int>?) {
r1 ?: 0
}
@@ -0,0 +1,4 @@
// !LANGUAGE: +InlineClasses -AllowResultInReturnType
fun result(): Result<Int> = TODO()
val resultP: Result<Int> = result()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +InlineClasses +AllowResultInReturnType
fun result(): Result<Int> = TODO()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
@OptIn(ExperimentalStdlibApi::class)
@@ -0,0 +1,19 @@
// !LANGUAGE: -FunctionTypesWithBigArity
// !DIAGNOSTICS: -UNUSED_PARAMETER
// SKIP_TXT
class A {
suspend fun foo(
p00: Long = 1, p01: A = A(), p02: A = A(), p03: A = A(), p04: A = A(), p05: A = A(), p06: A = A(), p07: A = A(), p08: A = A(), p09: A = A(),
p10: A = A(), p11: A = A(), p12: A = A(), p13: A = A(), p14: A = A(), p15: A = A(), p16: A = A(), p17: A = A(), p18: A = A(), p19: A = A(),
p20: A = A(), p21: A = A(), p22: A = A(), p23: A = A(), p24: A = A(), p25: A = A(), p26: A = A(), p27: A = A(), p28: A = A(), p29: String
): String {
return p29
}
}
suspend fun expectsLambdaWithBigArity(c: suspend (Long, Long, Long, Long, Long, Long, Long, Long, Long, Long,
Long, Long, Long, Long, Long, Long, Long, Long, Long, Long,
Long, Long, Long, Long, Long, Long, Long, Long, Long, String) -> String): String {
return c.invoke(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, "OK")
}
@@ -0,0 +1,13 @@
// !LANGUAGE: +NewInference
interface Inv
class Impl : Inv
class Scope<InterfaceT, ImplementationT : InterfaceT>(private val implClass: j.Class<ImplementationT>) {
fun foo(c: Collection<InterfaceT>) {
val hm = c.asSequence()
.<!INAPPLICABLE_CANDIDATE!>filter<!>(<!UNRESOLVED_REFERENCE!>implClass::isInstance<!>)
.<!INAPPLICABLE_CANDIDATE!>map<!>(<!UNRESOLVED_REFERENCE!>implClass::cast<!>)
.<!AMBIGUITY!>toSet<!>()
}
}
@@ -0,0 +1,14 @@
// SKIP_TXT
// COMMON_COROUTINES_TEST
import COROUTINES_PACKAGE.coroutineContext
val c = ::coroutineContext
fun test() {
c()
}
suspend fun test2() {
c()
}
@@ -0,0 +1,17 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
inline fun go1(f: () -> String) = f()
inline suspend fun go2(f: () -> String) = f()
fun builder(c: suspend () -> Unit) {}
suspend fun String.id(): String = this
fun box() {
val x = "f"
builder {
<!INAPPLICABLE_CANDIDATE!>go1<!>(x::id)
<!INAPPLICABLE_CANDIDATE!>go2<!>(x::id)
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ReleaseCoroutines
// !DIAGNOSTICS: -UNUSED_VARIABLE
@@ -0,0 +1,53 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// SKIP_TXT
import kotlin.coroutines.*
fun ordinal() {
kotlin.coroutines.coroutineContext
coroutineContext
}
suspend fun named() {
kotlin.coroutines.coroutineContext
coroutineContext
}
class A {
val coroutineContextNew = kotlin.coroutines.coroutineContext
val context = coroutineContext
}
class Controller {
fun ordinal() {
kotlin.coroutines.coroutineContext
coroutineContext
}
suspend fun named() {
kotlin.coroutines.coroutineContext
coroutineContext
}
suspend fun severalArgs(s: String, a: Any) {
kotlin.coroutines.coroutineContext
coroutineContext
}
}
fun builder(c: () -> CoroutineContext) = {}
fun builderSuspend(c: suspend () -> CoroutineContext) = {}
fun builderSeveralArgs(c: (Int, Int, Int) -> CoroutineContext) = {}
fun builderSuspendSeveralArgs(c: suspend (Int, Int, Int) -> CoroutineContext) = {}
fun test() {
builder { kotlin.coroutines.coroutineContext }
builder { coroutineContext }
builderSuspend { kotlin.coroutines.coroutineContext }
builderSuspend { coroutineContext }
builderSeveralArgs { _, _, _ -> kotlin.coroutines.coroutineContext }
builderSeveralArgs { _, _, _ -> coroutineContext }
builderSuspendSeveralArgs { _, _, _ -> kotlin.coroutines.coroutineContext }
builderSuspendSeveralArgs { _, _, _ -> coroutineContext }
}
@@ -0,0 +1,18 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: -Coroutines -ReleaseCoroutines
suspend fun suspendHere(): String = "OK"
fun builder(c: suspend () -> Unit) {
}
fun box(): String {
var result = ""
builder {
suspendHere()
}
return result
}
@@ -0,0 +1,18 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !LANGUAGE: warn:Coroutines -ReleaseCoroutines
suspend fun suspendHere(): String = "OK"
fun builder(c: suspend () -> Unit) {
}
fun box(): String {
var result = ""
builder {
suspendHere()
}
return result
}
@@ -0,0 +1,22 @@
import Host.bar
object Host {
suspend fun bar() {}
}
suspend fun foo() {}
fun noSuspend() {
foo()
bar()
}
class A {
init {
foo()
bar()
}
}
val x = foo()
val y = bar()
@@ -0,0 +1,8 @@
fun bar(d: Delegate): String {
val x: String by d
return x
}
class Delegate {
suspend operator fun getValue(thisRef: Any?, property: Any?): String = ""
}
@@ -0,0 +1,37 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
class Controller<T> {
suspend fun yield(t: T) {}
}
fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
val test1 = generate {
apply {
<!INAPPLICABLE_CANDIDATE!>yield<!>(4)
}
}
val test2 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(B)
apply {
<!INAPPLICABLE_CANDIDATE!>yield<!>(C)
}
}
val test3 = generate {
this.let {
<!INAPPLICABLE_CANDIDATE!>yield<!>(B)
}
apply {
<!INAPPLICABLE_CANDIDATE!>yield<!>(C)
}
}
interface A
object B : A
object C : A
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
@@ -0,0 +1,22 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
import kotlin.reflect.KSuspendFunction0
import kotlin.reflect.KSuspendFunction1
import kotlin.reflect.KFunction0
import kotlin.reflect.KFunction1
fun test0(serialize: KSuspendFunction0<Unit>) {}
fun test1(serialize: KSuspendFunction1<Int, Unit>) {}
suspend fun foo() {}
suspend fun bar(x: Int) {}
fun test() {
test0(::foo)
<!INAPPLICABLE_CANDIDATE!>test1<!>(::foo)
<!INAPPLICABLE_CANDIDATE!>test0<!>(::bar)
test1(::bar)
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
@@ -0,0 +1,19 @@
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
import kotlin.experimental.ExperimentalTypeInference
suspend fun main() {
iFlow { <!INAPPLICABLE_CANDIDATE!>emit<!>(1) }
}
@OptIn(ExperimentalTypeInference::class)
fun <K> iFlow(@BuilderInference block: suspend iFlowCollector<in K>.() -> Unit): iFlow<K> = TODO()
interface iFlowCollector<S> {
suspend fun emit(value: S)
}
interface iFlow<out V>
@@ -0,0 +1,25 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
@file:OptIn(ExperimentalTypeInference::class)
import kotlin.experimental.ExperimentalTypeInference
interface Controller<T> {
suspend fun yield(t: T) {}
fun justString(): String = ""
fun <Z> generidFun(t: Z) = t
}
fun <S> generate(@BuilderInference g: suspend Controller<S>.() -> Unit): S = TODO()
val test1 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(justString())
}
val test2 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(generidFun(2))
}
@@ -0,0 +1,38 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -UNUSED_EXPRESSION
@file:OptIn(ExperimentalTypeInference::class)
package a.b
import kotlin.experimental.ExperimentalTypeInference
class BatchInfo1(val batchSize: Int)
class BatchInfo2<T>(val data: T)
object Obj
fun test1() {
val a: Sequence<String> = sequence {
val x = BatchInfo1::class
val y = a.b.BatchInfo1::class
val z = Obj::class
val x1 = BatchInfo1::batchSize
val y1 = a.b.BatchInfo1::class
}
}
interface Scope<T> {
fun yield(t: T) {}
}
fun <S> generate(@BuilderInference g: Scope<S>.() -> Unit): S = TODO()
val test2 = generate {
{ <!INAPPLICABLE_CANDIDATE!>yield<!>("foo") }::class
}
val test3 = generate {
({ <!INAPPLICABLE_CANDIDATE!>yield<!>("foo") })::class
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
@@ -0,0 +1,43 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
@file:OptIn(ExperimentalTypeInference::class)
import kotlin.experimental.ExperimentalTypeInference
class GenericController<T> {
suspend fun yield(t: T) {}
}
@BuilderInference
suspend fun <K> GenericController<K>.yieldAll(s: Collection<K>) {}
fun <S> generate(@BuilderInference g: suspend GenericController<S>.() -> Unit): S = TODO()
val test1 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(4)
<!INAPPLICABLE_CANDIDATE!>yieldAll<!>(setOf(4, 5))
}
val test2 = generate {
<!INAPPLICABLE_CANDIDATE!>yieldAll<!>(setOf(B))
}
val test3 = generate {
<!INAPPLICABLE_CANDIDATE!>yieldAll<!>(setOf(B, C))
}
val test4 = generate {
<!INAPPLICABLE_CANDIDATE!>yieldAll<!>(setOf(B))
<!INAPPLICABLE_CANDIDATE!>yield<!>(C)
}
// Utils
fun <X> setOf(vararg x: X): Set<X> = TODO()
interface A
object B : A
object C : A
@@ -0,0 +1,62 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
@file:OptIn(ExperimentalTypeInference::class)
import kotlin.experimental.ExperimentalTypeInference
interface Base
interface Controller<T> : Base {
suspend fun yield(t: T) {}
}
fun <S> generate(@BuilderInference g: suspend Controller<S>.() -> Unit): S = TODO()
fun Base.baseExtension() {}
fun Controller<out Any?>.outNullableAnyExtension() {}
fun Controller<out Any>.outAnyExtension() {}
fun Controller<Any?>.invNullableAnyExtension() {}
fun <S> Controller<S>.genericExtension() {}
@BuilderInference
fun Controller<String>.safeExtension() {}
val test1 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>("foo")
baseExtension()
}
val test2 = generate {
baseExtension()
}
val test3 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(42)
outNullableAnyExtension()
}
val test4 = generate {
outNullableAnyExtension()
}
val test5 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(42)
outAnyExtension()
}
val test6 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>("bar")
<!INAPPLICABLE_CANDIDATE!>invNullableAnyExtension<!>()
}
val test7 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>("baz")
<!INAPPLICABLE_CANDIDATE!>genericExtension<!><Int>()
}
val test8 = generate {
<!INAPPLICABLE_CANDIDATE!>safeExtension<!>()
}
@@ -0,0 +1,52 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
@file:OptIn(ExperimentalTypeInference::class)
import kotlin.experimental.ExperimentalTypeInference
interface Base<K>
interface Controller<T> : Base<T> {
suspend fun yield(t: T) {}
}
interface SpecificController<T> : Base<String> {
suspend fun yield(t: T) {}
}
fun <S> generate(@BuilderInference g: suspend Controller<S>.() -> Unit): S = TODO()
fun <S> generateSpecific(@BuilderInference g: suspend SpecificController<S>.() -> Unit): S = TODO()
fun Base<*>.starBase() {}
fun Base<String>.stringBase() {}
val test1 = generate {
starBase()
<!INAPPLICABLE_CANDIDATE!>yield<!>("foo")
}
val test2 = generate {
starBase()
}
val test3 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>("bar")
<!INAPPLICABLE_CANDIDATE!>stringBase<!>()
}
val test4 = generateSpecific {
<!INAPPLICABLE_CANDIDATE!>yield<!>(42)
starBase()
}
val test5 = generateSpecific {
<!INAPPLICABLE_CANDIDATE!>yield<!>(42)
stringBase()
}
val test6 = generateSpecific {
stringBase()
}
@@ -0,0 +1,17 @@
// !LANGUAGE: -ExperimentalBuilderInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
interface Base
interface Controller<T> : Base {
suspend fun yield(t: T) {}
}
fun <S> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
suspend fun Base.baseExtension() {}
val test1 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>("foo")
baseExtension()
}
@@ -0,0 +1,36 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE
@file:OptIn(ExperimentalTypeInference::class)
import kotlin.experimental.ExperimentalTypeInference
class GenericController<T> {
suspend fun yield(t: T) {}
fun notYield(t: T) {}
suspend fun yieldBarReturnType(t: T) = t
fun barReturnType(): T = TODO()
}
fun <S> generate(@BuilderInference g: suspend GenericController<S>.() -> Unit): List<S> = TODO()
val test1 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(3)
}
val test2 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(3)
<!INAPPLICABLE_CANDIDATE!>notYield<!>(3)
}
val test3 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(3)
<!INAPPLICABLE_CANDIDATE!>yieldBarReturnType<!>(3)
}
val test4 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(3)
barReturnType()
}
@@ -0,0 +1,30 @@
// !LANGUAGE: -ExperimentalBuilderInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
class Builder<T> {
suspend fun add(t: T) {}
}
fun <S> build(g: suspend Builder<S>.() -> Unit): List<S> = TODO()
fun <S> wrongBuild(g: Builder<S>.() -> Unit): List<S> = TODO()
fun <S> Builder<S>.extensionAdd(s: S) {}
suspend fun <S> Builder<S>.safeExtensionAdd(s: S) {}
val member = build {
<!INAPPLICABLE_CANDIDATE!>add<!>(42)
}
val memberWithoutAnn = wrongBuild {
<!INAPPLICABLE_CANDIDATE!>add<!>(42)
}
val extension = build {
<!INAPPLICABLE_CANDIDATE!>extensionAdd<!>("foo")
}
val safeExtension = build {
<!INAPPLICABLE_CANDIDATE!>safeExtensionAdd<!>("foo")
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
@@ -0,0 +1,19 @@
// !WITH_NEW_INFERENCE
// SKIP_TXT
class StateMachine<Q> internal constructor() {
fun getInputStub(): Q = null as Q
}
fun <T> stateMachine(block: suspend StateMachine<T>.() -> Unit): StateMachine<T> {
return StateMachine<T>()
}
class Problem<F>(){
fun getInputStub(): F = null as F
fun createStateMachine(): StateMachine<F> = stateMachine {
val letter = getInputStub()
if (letter is Any)
println("yes")
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
suspend fun <T> threadSafeSuspendCallback(startAsync: (CompletionLambda<T>) -> CancellationLambda): T = TODO()
@@ -0,0 +1,27 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !LANGUAGE: +NewInference
import kotlin.experimental.ExperimentalTypeInference
interface In<in E> {
fun send(element: E)
}
class InImpl<E> : In<E> {
override fun send(element: E) {}
}
@OptIn(ExperimentalTypeInference::class)
public fun <T> builder(@BuilderInference block: In<T>.() -> Unit) {
InImpl<T>().block()
}
suspend fun yield() {}
fun test() {
builder {
send(run {
yield() // No error but `yield` is not inside "suspension" context actually
})
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -0,0 +1,35 @@
// !LANGUAGE: +NewInference
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
// ISSUE: KT-35684
import kotlin.experimental.ExperimentalTypeInference
fun test_1() {
<!DEBUG_INFO_EXPRESSION_TYPE("kotlin.Nothing")!>sequence {
<!INAPPLICABLE_CANDIDATE!>yield<!>(<!DEBUG_INFO_EXPRESSION_TYPE("Inv<kotlin.Any?>")!>materialize()<!>)
<!INAPPLICABLE_CANDIDATE!>yield<!>(materialize<Int>())
}<!>
}
fun test_2() {
sequence {
<!INAPPLICABLE_CANDIDATE!>yield<!>(materialize())
}
}
fun test_3() {
sequence {
<!INAPPLICABLE_CANDIDATE!>yield<!>(materialize<Int>())
materialize()
}
}
@OptIn(ExperimentalTypeInference::class)
fun <U> sequence(@BuilderInference block: suspend Inv<U>.() -> Unit): U = null!!
interface Inv<T> {
fun yield(element: T)
}
fun <K> materialize(): Inv<K> = TODO()
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
@@ -0,0 +1,20 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
import kotlin.experimental.ExperimentalTypeInference
class TypeDefinition<KotlinType : Any> {
fun parse(parser: (serializedValue: String) -> KotlinType?): Unit = TODO()
fun serialize(parser: (value: KotlinType) -> Any?): Unit = TODO()
}
@OptIn(ExperimentalTypeInference::class)
fun <KotlinType : Any> defineType(@BuilderInference definition: TypeDefinition<KotlinType>.() -> Unit): Unit = TODO()
fun main() {
defineType {
parse { it.toInt() }
serialize { it.toString() }
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
@OptIn(ExperimentalStdlibApi::class)
@@ -0,0 +1,34 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE -UNUSED_EXPRESSION
import kotlin.experimental.ExperimentalTypeInference
abstract class AnimationVector
class AnimationVector1D : AnimationVector()
interface PropKey<T, V : AnimationVector>
class IntPropKey : PropKey<Int, AnimationVector1D>
abstract class AnimationBuilder<T>
abstract class DurationBasedAnimationBuilder<T> : AnimationBuilder<T>()
class TweenBuilder<T> : DurationBasedAnimationBuilder<T>()
class TransitionSpec<S> {
fun <T> tween(init: TweenBuilder<T>.() -> Unit): DurationBasedAnimationBuilder<T> = TweenBuilder<T>().apply(init)
infix fun <T, V : AnimationVector> PropKey<T, V>.using(builder: AnimationBuilder<T>) {}
}
class TransitionDefinition<T> {
fun transition(fromState: T? = null, toState: T? = null, init: TransitionSpec<T>.() -> Unit) {}
}
@OptIn(ExperimentalTypeInference::class)
fun <T> transitionDefinition(@BuilderInference init: TransitionDefinition<T>.() -> Unit) = TransitionDefinition<T>().apply(init)
fun main() {
val intProp = IntPropKey()
val defn = transitionDefinition {
transition(1, 2) {
intProp using tween {
}
}
}
<!DEBUG_INFO_EXPRESSION_TYPE("TransitionDefinition<kotlin.Any?>")!>defn<!>
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
val configurations4 = listOf(
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
@@ -0,0 +1,37 @@
// !DIAGNOSTICS: -UNCHECKED_CAST -EXPERIMENTAL_API_USAGE_ERROR -UNUSED_PARAMETER
class Bar
fun <T> materialize() = null as T
interface FlowCollector<in T> {
suspend fun emit(value: T)
}
interface Flow<T>
public fun <T> flow(@BuilderInference block: suspend FlowCollector<T>.() -> Unit) = materialize<Flow<T>>()
fun foo(total: Int, next: Int) = 10
fun foo(total: Int, next: Float) = 10
fun foo(total: Float, next: Int) = 10
fun call(x: String) {}
suspend fun foo(x: Int) = flow {
var y = 1
y += if (x > 2) 1 else 2
var newValue = 1
newValue += listOf<Int>().asSequence().fold(0) { total, next ->
<!INAPPLICABLE_CANDIDATE!>call<!>(11)
total + next
}
newValue += listOf<Int>().asSequence().fold(0, fun(total, next): Int { return total + next })
newValue += listOf<Int>().asSequence().fold(0, fun(total, next) = total + next)
newValue += listOf<Int>().asSequence().fold(0, ::foo)
emit(materialize<Bar>())
newValue += listOf<Int>().asSequence().fold(0) { total, next -> total + next }
}
@@ -0,0 +1,42 @@
// !DIAGNOSTICS: -UNUSED_ANONYMOUS_PARAMETER -UNUSED_PARAMETER
fun foo(total: Int, next: Int) = 10
fun foo(total: Int, next: Float) = 10
fun foo(total: Float, next: Int) = 10
fun call(x: String) {}
fun foo(x: Float, y: Float) = {
var newValue = 1
newValue += listOf<Int>().asSequence().fold(0) { total, next ->
<!INAPPLICABLE_CANDIDATE!>call<!>(11)
total + next
}
newValue += listOf<Int>().asSequence().fold(0, fun(total, next): Int { return total + next })
newValue += listOf<Int>().asSequence().fold(0, fun(total, next) = total + next)
newValue += listOf<Int>().asSequence().fold(0, ::foo)
}
class A {
operator fun plus(x: Int) = A()
operator fun plusAssign(x: Float) {}
}
fun <T> id(x: T) = x
fun foo2() = {
var x = A()
<!INAPPLICABLE_CANDIDATE!>x += { "" }<!>
var y = A()
y += 1
}
class B {
operator fun plus(x: () -> String) = A()
operator fun plusAssign(x: () -> Int) {}
}
fun foo3(x: B) = {
<!VARIABLE_EXPECTED!>x<!> += { "" }
<!VARIABLE_EXPECTED!>x<!> += id { "" }
}
@@ -0,0 +1,20 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER
open class A
operator fun <T> T.plus(x: (T) -> Int) = A()
operator fun <T> T.plusAssign(x: (Int) -> T) {}
fun foo(total: Int) = 10
fun foo(total: Float) = 10
fun foo(total: String) = 10
fun <T> id(x: T) = x
fun main() {
var newValue = A()
<!INAPPLICABLE_CANDIDATE!>newValue += id { total -> A() }<!>
<!INAPPLICABLE_CANDIDATE!>newValue += id(fun(total) = A())<!>
<!INAPPLICABLE_CANDIDATE!>newValue += id(fun(total): A { return A() })<!>
<!ASSIGN_OPERATOR_AMBIGUITY!>newValue += id(::foo)<!>
}
@@ -0,0 +1,20 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
import kotlin.experimental.ExperimentalTypeInference
fun test() {
flow {
<!INAPPLICABLE_CANDIDATE!>emit<!>(42)
kotlin.coroutines.coroutineContext
}
}
@OptIn(ExperimentalTypeInference::class)
fun <T> flow(@BuilderInference block: suspend FlowCollector<T>.() -> Unit): Flow<T> = TODO()
interface Flow<out T>
interface FlowCollector<in T> {
suspend fun emit(value: T)
}
@@ -0,0 +1,22 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
@file:OptIn(ExperimentalTypeInference::class)
import kotlin.experimental.ExperimentalTypeInference
class GenericController<T> {
suspend fun yield(t: T) {}
}
fun <S> generate(@BuilderInference g: suspend GenericController<S>.() -> Unit): List<S> = TODO()
val test1 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(generate {
yield(generate {
yield(generate {
yield(3)
})
})
})
}
@@ -0,0 +1,24 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
@file:OptIn(ExperimentalTypeInference::class)
import kotlin.experimental.ExperimentalTypeInference
class GenericController<T> {
suspend fun yield(t: T) {}
}
fun <S> generate(@BuilderInference g: suspend GenericController<S>.() -> Unit): List<S> = TODO()
@BuilderInference
suspend fun <S> GenericController<List<S>>.yieldGenerate(g: suspend GenericController<S>.() -> Unit): Unit = TODO()
val test1 = generate {
// TODO: KT-15185
<!INAPPLICABLE_CANDIDATE!>yieldGenerate<!> {
<!INAPPLICABLE_CANDIDATE!>yield<!>(4)
}
}
@@ -0,0 +1,37 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
// FILE: annotation.kt
package kotlin
annotation class BuilderInference
// FILE: test.kt
class Builder<T> {
fun add(t: T) {}
}
fun <S> build(@BuilderInference g: Builder<S>.() -> Unit): List<S> = TODO()
fun <S> wrongBuild(g: Builder<S>.() -> Unit): List<S> = TODO()
fun <S> Builder<S>.extensionAdd(s: S) {}
@BuilderInference
fun <S> Builder<S>.safeExtensionAdd(s: S) {}
val member = build {
<!INAPPLICABLE_CANDIDATE!>add<!>(42)
}
val memberWithoutAnn = wrongBuild {
<!INAPPLICABLE_CANDIDATE!>add<!>(42)
}
val extension = build {
<!INAPPLICABLE_CANDIDATE!>extensionAdd<!>("foo")
}
val safeExtension = build {
<!INAPPLICABLE_CANDIDATE!>safeExtensionAdd<!>("foo")
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
class Controller
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER -UNUSED_VARIABLE
@@ -0,0 +1,34 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
@file:OptIn(ExperimentalTypeInference::class)
import kotlin.experimental.ExperimentalTypeInference
class GenericController<T> {
suspend fun yield(t: T) {}
suspend fun yieldSet(t: Set<T>) {}
suspend fun yieldVararg(vararg t: T) {}
}
fun <S> generate(@BuilderInference g: suspend GenericController<S>.() -> Unit): S = TODO()
val test1 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(4)
}
val test2 = generate {
<!INAPPLICABLE_CANDIDATE!>yieldSet<!>(setOf(1, 2, 3))
}
val test3 = generate {
<!INAPPLICABLE_CANDIDATE!>yieldVararg<!>(1, 2, 3)
}
val test4 = generate {
<!INAPPLICABLE_CANDIDATE!>yieldVararg<!>(1, 2, "")
}
// Util function
fun <X> setOf(vararg x: X): Set<X> = TODO()
@@ -0,0 +1,24 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
@file:OptIn(ExperimentalTypeInference::class)
import kotlin.experimental.ExperimentalTypeInference
class Controller<T> {
suspend fun yield(t: T) {}
}
fun <S> generate(@BuilderInference g: suspend Controller<S>.() -> Unit): S = TODO()
class A
val test1 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(A)
}
val test2: Int = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(A())
}
@@ -0,0 +1,13 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
class Controller<T : Number> {
suspend fun yield(t: T) {}
}
fun <S : Number> generate(g: suspend Controller<S>.() -> Unit): S = TODO()
val test = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>("foo")
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_PARAMETER
@@ -0,0 +1,17 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
@file:OptIn(ExperimentalTypeInference::class)
import kotlin.experimental.ExperimentalTypeInference
class GenericController<T>
fun <S> generate(@BuilderInference g: suspend GenericController<S>.() -> Unit): List<S> = TODO()
@BuilderInference
suspend fun GenericController<List<String>>.test() {}
val test1 = generate {
<!INAPPLICABLE_CANDIDATE!>test<!>()
}
@@ -0,0 +1,33 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !WITH_NEW_INFERENCE
// FILE: annotation.kt
package kotlin
annotation class BuilderInference
// FILE: test.kt
class GenericController<T> {
suspend fun yield(t: T) {}
}
suspend fun <S> GenericController<S>.extensionYield(s: S) {}
@BuilderInference
suspend fun <S> GenericController<S>.safeExtensionYield(s: S) {}
fun <S> generate(@BuilderInference g: suspend GenericController<S>.() -> Unit): List<S> = TODO()
val normal = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(42)
}
val extension = generate {
<!INAPPLICABLE_CANDIDATE!>extensionYield<!>("foo")
}
val safeExtension = generate {
<!INAPPLICABLE_CANDIDATE!>safeExtensionYield<!>("foo")
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +NewInference
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
@@ -0,0 +1,21 @@
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_ANONYMOUS_PARAMETER -UNUSED_VARIABLE
// !WITH_NEW_INFERENCE
// NI_EXPECTED_FILE
class GenericController<T> {
suspend fun yield(t: T) {}
}
fun <S> generate(g: suspend GenericController<S>.(S) -> Unit): S = TODO()
val test1 = generate {
<!INAPPLICABLE_CANDIDATE!>yield<!>(4)
}
val test2 = generate<Int> {
yield(4)
}
val test3 = generate { bar: Int ->
yield(4)
}
@@ -0,0 +1,34 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// COMMON_COROUTINES_TEST
// WITH_COROUTINES
// SKIP_TXT
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
// Function is NOT suspend
// parameter is crossinline
// parameter is NOT suspend
// Block is allowed to be called inside the body of owner inline function
// Block is allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls NOT possible inside lambda matching to the parameter
inline fun test(crossinline c: () -> Unit) {
c()
val o = object: Runnable {
override fun run() {
c()
}
}
val l = { c() }
c.<!UNRESOLVED_REFERENCE!>startCoroutine<!>(EmptyContinuation)
}
suspend fun calculate() = "OK"
fun box() {
test {
calculate()
}
}
@@ -0,0 +1,38 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE
// COMMON_COROUTINES_TEST
// SKIP_TXT
// WITH_COROUTINES
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
interface SuspendRunnable {
suspend fun run()
}
// Function is NOT suspend
// parameter is crossinline
// parameter is suspend
// Block is NOT allowed to be called inside the body of owner inline function
// Block is allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls possible inside lambda matching to the parameter
inline fun test(crossinline c: suspend () -> Unit) {
c()
val o = object : SuspendRunnable {
override suspend fun run() {
c()
}
}
val l: suspend () -> Unit = { c() }
c.startCoroutine(EmptyContinuation)
}
suspend fun calculate() = "OK"
fun box() {
test {
calculate()
}
}
@@ -0,0 +1,33 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE
// COMMON_COROUTINES_TEST
// SKIP_TXT
// WITH_COROUTINES
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
// Function is NOT suspend
// parameter is noinline
// parameter is NOT suspend
// Block is allowed to be called inside the body of owner inline function
// Block is allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls NOT possible inside lambda matching to the parameter
inline fun test(noinline c: () -> Unit) {
c()
val o = object: Runnable {
override fun run() {
c()
}
}
val l = { c() }
c.<!UNRESOLVED_REFERENCE!>startCoroutine<!>(EmptyContinuation)
}
suspend fun calculate() = "OK"
fun box() {
test {
calculate()
}
}
@@ -0,0 +1,38 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE
// COMMON_COROUTINES_TEST
// SKIP_TXT
// WITH_COROUTINES
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
interface SuspendRunnable {
suspend fun run()
}
// Function is NOT suspend
// parameter is noinline
// parameter is suspend
// Block is NOT allowed to be called inside the body of owner inline function
// Block is allowed to be called from nested classes/lambdas (as common crossinlines)
// It is possible to call startCoroutine on the parameter
// suspend calls possible inside lambda matching to the parameter
inline fun test(noinline c: suspend () -> Unit) {
c()
val o = object : SuspendRunnable {
override suspend fun run() {
c()
}
}
val l: suspend () -> Unit = { c() }
c.startCoroutine(EmptyContinuation)
}
suspend fun calculate() = "OK"
fun box() {
test {
calculate()
}
}
@@ -0,0 +1,40 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// COMMON_COROUTINES_TEST
// SKIP_TXT
// WITH_COROUTINES
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
// Function is NOT suspend
// parameter is inline
// parameter is NOT suspend
// Block is allowed to be called inside the body of owner inline function
// Block is NOT allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls possible inside lambda matching to the parameter
inline fun test(c: () -> Unit) {
c()
val o = object : Runnable {
override fun run() {
c()
}
}
val l = { c() }
c.<!UNRESOLVED_REFERENCE!>startCoroutine<!>(EmptyContinuation)
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
suspend fun calculate() = "OK"
fun box() {
builder {
test {
calculate()
}
}
}
@@ -0,0 +1,40 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE -UNUSED_PARAMETER
// COMMON_COROUTINES_TEST
// SKIP_TXT
// WITH_COROUTINES
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
interface SuspendRunnable {
suspend fun run()
}
// Function is NOT suspend
// parameter is inline
// parameter is suspend
// Block is NOT allowed to be called inside the body of owner inline function
// Block is NOT allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls possible inside lambda matching to the parameter
inline fun test(c: suspend () -> Unit) {
c()
val o = object: SuspendRunnable {
override suspend fun run() {
c()
}
}
val l: suspend () -> Unit = { c() }
c.startCoroutine(EmptyContinuation)
}
fun builder(c: suspend () -> Unit) {}
suspend fun calculate() = "OK"
fun box() {
test {
calculate()
}
}
@@ -0,0 +1,39 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE
// COMMON_COROUTINES_TEST
// SKIP_TXT
// WITH_COROUTINES
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
// Function is suspend
// parameter is crossinline
// parameter is NOT suspend
// Block is allowed to be called inside the body of owner inline function
// Block is allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls NOT possible inside lambda matching to the parameter
suspend inline fun test(crossinline c: () -> Unit) {
c()
val o = object : Runnable {
override fun run() {
c()
}
}
val l = { c() }
c.<!UNRESOLVED_REFERENCE!>startCoroutine<!>(EmptyContinuation)
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
suspend fun calculate() = "OK"
fun box() {
builder {
test {
calculate()
}
}
}
@@ -0,0 +1,41 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE
// COMMON_COROUTINES_TEST
// SKIP_TXT
// WITH_COROUTINES
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
interface SuspendRunnable {
suspend fun run()
}
// Function is suspend
// parameter is crossinline
// parameter is suspend
// Block is allowed to be called inside the body of owner inline function
// Block is allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls possible inside lambda matching to the parameter
suspend inline fun test(crossinline c: suspend () -> Unit) {
c()
val o = object : SuspendRunnable {
override suspend fun run() {
c()
}
}
val l: suspend () -> Unit = { c() }
c.startCoroutine(EmptyContinuation)
}
fun builder(c: suspend () -> Unit) {}
suspend fun calculate() = "OK"
fun box() {
builder {
test {
calculate()
}
}
}
@@ -0,0 +1,39 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE
// COMMON_COROUTINES_TEST
// SKIP_TXT
// WITH_COROUTINES
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
// Function is suspend
// parameter is noinline
// parameter is NOT suspend
// Block is allowed to be called inside the body of owner inline function
// Block is allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls NOT possible inside lambda matching to the parameter
suspend inline fun test(noinline c: () -> Unit) {
c()
val o = object : Runnable {
override fun run() {
c()
}
}
val l = { c() }
c.<!UNRESOLVED_REFERENCE!>startCoroutine<!>(EmptyContinuation)
}
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
suspend fun calculate() = "OK"
fun box() {
builder {
test {
calculate()
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_VARIABLE -NOTHING_TO_INLINE -UNUSED_PARAMETER
// COMMON_COROUTINES_TEST
// SKIP_TXT
@@ -0,0 +1,37 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER
// COMMON_COROUTINES_TEST
// SKIP_TXT
// WITH_COROUTINES
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
// Function is suspend
// parameter is inline
// parameter is NOT suspend
// Block is allowed to be called inside the body of owner inline function
// Block is NOT allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls possible inside lambda matching to the parameter
suspend inline fun test(c: () -> Unit) {
c()
val o = object: Runnable {
override fun run() {
c()
}
}
val l = { c() }
c.<!UNRESOLVED_REFERENCE!>startCoroutine<!>(EmptyContinuation)
}
suspend fun calculate() = "OK"
fun builder(c: suspend () -> Unit) {}
fun box() {
builder {
test {
calculate()
}
}
}
@@ -0,0 +1,42 @@
// !DIAGNOSTICS: -UNUSED_VARIABLE -UNUSED_PARAMETER -NOTHING_TO_INLINE
// COMMON_COROUTINES_TEST
// SKIP_TXT
// WITH_COROUTINES
import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import helpers.*
interface SuspendRunnable {
suspend fun run()
}
// Function is suspend
// parameter is inline
// parameter is suspend
// Block is allowed to be called inside the body of owner inline function
// Block is NOT allowed to be called from nested classes/lambdas (as common crossinlines)
// It is NOT possible to call startCoroutine on the parameter
// suspend calls possible inside lambda matching to the parameter
suspend inline fun test(c: suspend () -> Unit) {
c()
val o = object: SuspendRunnable {
override suspend fun run() {
c()
}
}
val l: suspend () -> Unit = { c() }
c.startCoroutine(EmptyContinuation)
}
fun builder(c: suspend () -> Unit) {
}
suspend fun calculate() = "OK"
fun box() {
builder {
test {
calculate()
}
}
}
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER
// !CHECK_TYPE
class Controller {
@@ -0,0 +1,5 @@
// SKIP_TXT
import kotlin.reflect.*
class A: KSuspendFunction0<Unit> {}
@@ -0,0 +1,19 @@
// !WITH_NEW_INFERENCE
// SKIP_TXT
// WITH_RUNTIME
import kotlin.coroutines.*
interface Job : CoroutineContext.Element {}
interface Deferred<out T> : Job {
suspend fun await(): T
}
fun <T> async(block: suspend () -> T): Deferred<T> = TODO()
suspend fun fib(n: Long) =
async {
when {
n < 2 -> n
else -> fib(n - 1).<!UNRESOLVED_REFERENCE!>await<!>() <!AMBIGUITY!>+<!> fib(n - 2).<!UNRESOLVED_REFERENCE!>await<!>()
}
}
@@ -0,0 +1,34 @@
// !LANGUAGE: +NewInference
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_EXPRESSION -UNUSED_PARAMETER -UNUSED_VARIABLE
import kotlin.experimental.ExperimentalTypeInference
fun test1() {
sequence {
val a: Array<Int> = arrayOf(1, 2, 3)
val b = arrayOf(1, 2, 3)
}
}
fun test2() = sequence { arrayOf(1, 2, 3) }
class Foo<T>
fun <T> f1(f: Foo<T>.() -> Unit) {}
@OptIn(ExperimentalTypeInference::class)
fun <T> f2(@BuilderInference f: Foo<T>.() -> Unit) {
}
fun test3() {
f1 {
val a: Array<Int> = arrayOf(1, 2, 3)
}
f2 {
val a: Array<Int> = arrayOf(1, 2, 3)
}
}
@@ -0,0 +1,6 @@
val foo = iterator {
<!INAPPLICABLE_CANDIDATE!>yield<!>(0)
val nullable: String? = null
nullable.<!INAPPLICABLE_CANDIDATE!>length<!>
nullable.<!INAPPLICABLE_CANDIDATE!>get<!>(2)
}
@@ -0,0 +1,24 @@
// !USE_EXPERIMENTAL: kotlin.RequiresOptIn
// !DIAGNOSTICS: -UNUSED_VARIABLE
import kotlin.experimental.ExperimentalTypeInference
@OptIn(ExperimentalTypeInference::class)
fun <E> myBuildList(@BuilderInference builderAction: MutableList<E>.() -> Unit) {
ArrayList<E>().builderAction()
}
@OptIn(ExperimentalStdlibApi::class)
fun main() {
val newList1 = myBuildList {
<!INAPPLICABLE_CANDIDATE!>addAll<!>(
listOf(1).map { <!INAPPLICABLE_CANDIDATE!>Foo<!>(null) }
)
}
val newList2 = buildList {
<!INAPPLICABLE_CANDIDATE!>addAll<!>(listOf(1,2,3).map{ <!INAPPLICABLE_CANDIDATE!>Foo<!>(null) })
}
}
class Foo(val notNullProp: String)
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// FULL_JDK
import java.util.*
@@ -0,0 +1,53 @@
// !LANGUAGE: -SuspendConversion
// !WITH_NEW_INFERENCE
// !CHECK_TYPE
// !DIAGNOSTICS: -UNUSED_PARAMETER -ASSIGNED_BUT_NEVER_ACCESSED_VARIABLE -UNUSED_VALUE -UNUSED_VARIABLE
fun builder(c: suspend () -> Int) = 1
fun <T> genericBuilder(c: suspend () -> T): T = null!!
fun unitBuilder(c: suspend () -> Unit) = 1
fun emptyBuilder(c: suspend () -> Unit) = 1
fun <T> manyArgumentsBuilder(
c1: suspend () -> Unit,
c2: suspend () -> T,
c3: suspend () -> Int
):T = null!!
fun severalParamsInLambda(c: suspend (String, Int) -> Unit) {}
fun foo() {
builder({ 1 })
builder { 1 }
val x = { 1 }
<!INAPPLICABLE_CANDIDATE!>builder<!>(x)
builder({1} as (suspend () -> Int))
var i: Int = 1
i = genericBuilder({ 1 })
i = genericBuilder { 1 }
genericBuilder { 1 }
genericBuilder<Int> { 1 }
genericBuilder<Int> { "" }
val y = { 1 }
<!INAPPLICABLE_CANDIDATE!>genericBuilder<!>(y)
unitBuilder {}
unitBuilder { 1 }
unitBuilder({})
unitBuilder({ 1 })
manyArgumentsBuilder({}, { "" }) { 1 }
val s: String = manyArgumentsBuilder({}, { "" }) { 1 }
manyArgumentsBuilder<String>({}, { "" }, { 1 })
manyArgumentsBuilder<String>({}, { 1 }, { 2 })
severalParamsInLambda { x, y ->
x checkType { _<String>() }
y checkType { _<Int>() }
}
}
@@ -0,0 +1,6 @@
interface AsyncVal { suspend fun getVal(): Int = 1}
interface SyncVal { fun getVal(): Int = 1 }
class MixSuspend : AsyncVal, SyncVal {
}
@@ -0,0 +1,76 @@
// !LANGUAGE: +ReleaseCoroutines
// SKIP_TXT
fun <R> suspend(block: suspend () -> R): suspend () -> R = block
class A {
infix fun <R> suspend(block: suspend () -> R): suspend () -> R = block
}
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class Ann
fun bar() {
suspend {
println()
}
@Ann suspend {
println()
}
suspend @Ann {
println()
}
suspend() {
println()
}
suspend({ println() })
suspend<Unit> {
println()
}
val w: (suspend () -> Int) -> Any? = ::suspend
A().suspend {
println()
}
A().suspend() {
println()
}
A().suspend({ println() })
A().suspend<Unit> {
println()
}
with(A()) {
suspend {
println()
}
suspend() {
println()
}
suspend({ println() })
suspend<Unit> {
println()
}
}
A() suspend {
println()
}
A() suspend ({
println()
})
}
@@ -0,0 +1,84 @@
// !LANGUAGE: +ReleaseCoroutines
// SKIP_TXT
fun <R> suspend(block: R) = block
class A {
infix fun <R> suspend(block: R) = block
}
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class Ann
fun bar() {
suspend {
println()
}
@Ann suspend {
println()
}
suspend @Ann {
println()
}
suspend() {
println()
}
suspend({ println() })
suspend<suspend () -> Unit> {
println()
}
suspend<Nothing?>(null)
val w: (Any?) -> Any? = ::suspend
A().suspend {
println()
}
A().suspend() {
println()
}
A().suspend({ println() })
A().suspend<suspend () -> Unit> {
println()
}
A().suspend<Nothing?>(null)
with(A()) {
suspend {
println()
}
suspend() {
println()
}
suspend({ println() })
suspend<suspend () -> Unit> {
println()
}
suspend<Nothing?>(null)
}
A() suspend {
println()
}
A() suspend ({
println()
})
A() suspend ""
}
@@ -0,0 +1,9 @@
// FILE: 1.kt
// COMMON_COROUTINES_TEST
fun test(c: Continuation<Unit>) {}
// FILE: 2.kt
import COROUTINES_PACKAGE.*
fun test2(c: Continuation<Unit>) {}
@@ -0,0 +1,81 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
import Host.suspendFromObject
suspend fun suspendHere() = 1
suspend fun <T> another(a: T) = 1
object Host {
suspend fun suspendFromObject() = 1
}
fun <T> builder(c: suspend () -> Unit) { }
inline fun run(x: () -> Unit) {}
inline fun runCross(crossinline x: () -> Unit) {}
fun noinline(x: () -> Unit) {}
fun foo() {
var result = 1
builder<String> {
suspendHere()
suspendFromObject()
another("")
another(1)
result += suspendHere()
result += suspendFromObject()
run {
result += suspendHere()
result += suspendFromObject()
run {
suspendHere()
suspendFromObject()
}
}
runCross {
result += suspendHere()
result += suspendFromObject()
runCross {
suspendHere()
suspendFromObject()
}
}
noinline {
result += suspendHere()
result += suspendFromObject()
noinline {
suspendHere()
suspendFromObject()
}
}
class A {
fun bar() {
suspendHere()
suspendFromObject()
}
}
object : Any() {
fun baz() {
suspendHere()
suspendFromObject()
}
}
builder<Int> {
suspendHere()
suspendFromObject()
another(1)
another("")
}
}
}
@@ -0,0 +1,45 @@
// !LANGUAGE: +ReleaseCoroutines
// SKIP_TXT
fun bar() {
suspend {
println()
}
@Ann suspend {
println()
}
suspend @Ann {
println()
}
kotlin.suspend {
}
suspend() {
println()
}
suspend({ println() })
suspend<Unit> {
println()
}
val w: (suspend () -> Int) -> Any? = ::suspend
}
@Target(AnnotationTarget.EXPRESSION)
@Retention(AnnotationRetention.SOURCE)
annotation class Ann
fun main(suspend: WLambdaInvoke) {
suspend {}
}
class WLambdaInvoke {
operator fun invoke(l: () -> Unit) {}
}
@@ -0,0 +1,30 @@
// !LANGUAGE: +ReleaseCoroutines
// SKIP_TXT
import kotlin.suspend as suspendLambda
fun bar() {
suspend {
println()
}
kotlin.suspend {
}
suspendLambda {
println()
}
suspendLambda() {
println()
}
suspendLambda({ println() })
suspendLambda<Unit> {
println()
}
val w: (suspend () -> Int) -> Any? = ::suspendLambda
}
@@ -0,0 +1,60 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER
// SKIP_TXT
import kotlin.reflect.KProperty
class A {
suspend operator fun get(x: Int) = 1
suspend operator fun set(x: Int, v: String) {}
operator suspend fun contains(y: String): Boolean = true
suspend operator fun unaryPlus() = this
suspend operator fun unaryMinus() = this
suspend operator fun not() = this
suspend operator fun inc() = this
suspend operator fun dec() = this
suspend operator fun plus(a: A) = a
suspend operator fun minus(a: A) = a
suspend operator fun times(a: A) = a
suspend operator fun div(a: A) = a
suspend operator fun rem(a: A) = a
suspend operator fun rangeTo(a: A) = a
suspend operator fun invoke(a: A) = a
suspend operator fun compareTo(a: A) = hashCode().compareTo(a.hashCode())
suspend operator fun iterator() = this
suspend operator fun hasNext() = false
suspend operator fun next() = this
suspend operator fun contains(b: A) = this == b
suspend operator fun get(a: A) = a
suspend operator fun equals(a: A) = a === this
suspend operator fun set(a: A, b: A) {}
suspend operator fun provideDelegate(a: A, p: KProperty<*>) = a
suspend operator fun getValue(a: A, p: KProperty<*>) = a
suspend operator fun setValue(a: A, p: KProperty<*>, b: A) {}
}
class B
suspend operator fun B.get(x: Int) =1
suspend operator fun B.set(x: Int, v: String) {}
operator suspend fun B.contains(y: String): Boolean = true
class C {
suspend fun get(x: Int) = 1
suspend fun set(x: Int, v: String) {}
suspend fun contains(y: String): Boolean = true
}
class D
suspend fun D.get(x: Int) =1
suspend fun D.set(x: Int, v: String) {}
suspend fun D.contains(y: String): Boolean = true
@@ -0,0 +1,8 @@
// !LANGUAGE: +ReleaseCoroutines
// SKIP_TXT
import kotlin.coroutines.experimental.coroutineContext
suspend fun test() {
coroutineContext
}
@@ -0,0 +1,38 @@
// !API_VERSION: 1.2
// !DIAGNOSTICS: -PRE_RELEASE_CLASS, -UNUSED_PARAMETER
// !LANGUAGE: +ReleaseCoroutines
// !WITH_NEW_INFERENCE
// SKIP_TXT
suspend fun dummy() {}
// TODO: Forbid
fun builder(c: suspend () -> Unit) {}
suspend fun test1() {
kotlin.coroutines.coroutineContext
kotlin.coroutines.experimental.coroutineContext
suspend {}()
dummy()
val c: suspend () -> Unit = {}
c()
builder {}
}
fun test2() {
kotlin.coroutines.experimental.buildSequence<Int> {
yield(1)
}
kotlin.sequences.buildSequence<Int> {
yield(1)
}
}
suspend fun test3(): Unit = kotlin.coroutines.experimental.suspendCoroutine { _ -> Unit }
suspend fun test4(): Unit = kotlin.coroutines.suspendCoroutine { _ -> Unit }
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !LANGUAGE: +ReleaseCoroutines
// SKIP_TXT
@@ -1,3 +1,4 @@
// FIR_IDENTICAL
// !DIAGNOSTICS: -UNUSED_PARAMETER -SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE
// COMMON_COROUTINES_TEST
@@ -0,0 +1,130 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE
// COMMON_COROUTINES_TEST
interface SuperInterface
@COROUTINES_PACKAGE.RestrictsSuspension
open class RestrictedController : SuperInterface
class SubClass : RestrictedController()
suspend fun Any?.extAny() {}
suspend fun SuperInterface.extSuper() {}
suspend fun RestrictedController.ext() {}
suspend fun SubClass.extSub() {}
class A {
suspend fun Any?.memExtAny() {}
suspend fun SuperInterface.memExtSuper() {}
suspend fun RestrictedController.memExt() {}
suspend fun SubClass.memExtSub() {}
}
fun generate1(f: suspend SuperInterface.() -> Unit) {}
fun generate2(f: suspend RestrictedController.() -> Unit) {}
fun generate3(f: suspend SubClass.() -> Unit) {}
fun A.test() {
generate1 {
extAny()
memExtAny()
extSuper()
memExtSuper()
with(A()) {
extAny()
memExtAny()
extSuper()
memExtSuper()
}
}
generate2 {
extAny()
memExtAny()
extSuper()
memExtSuper()
ext()
memExt()
with(A()) {
extAny()
memExtAny()
extSuper()
memExtSuper()
ext()
memExt()
}
}
generate3 {
extAny()
memExtAny()
extSuper()
memExtSuper()
ext()
memExt()
extSub()
memExtSub()
with(A()) {
extAny()
memExtAny()
extSuper()
memExtSuper()
ext()
memExt()
extSub()
memExtSub()
}
}
suspend fun SuperInterface.fun1() {
extAny()
memExtAny()
extSuper()
memExtSuper()
with(A()) {
extAny()
memExtAny()
extSuper()
memExtSuper()
}
}
suspend fun RestrictedController.fun2() {
extAny()
memExtAny()
extSuper()
memExtSuper()
ext()
memExt()
with(A()) {
extAny()
memExtAny()
extSuper()
memExtSuper()
ext()
memExt()
}
}
suspend fun SubClass.fun3() {
extAny()
memExtAny()
extSuper()
memExtSuper()
ext()
memExt()
extSub()
memExtSub()
with(A()) {
extAny()
memExtAny()
extSuper()
memExtSuper()
ext()
memExt()
extSub()
memExtSub()
}
}
}
@@ -0,0 +1,62 @@
// COMMON_COROUTINES_TEST
// SKIP_TXT
@COROUTINES_PACKAGE.RestrictsSuspension
class RestrictedController {
suspend fun member() {
ext()
member()
memberExt()
}
suspend fun RestrictedController.memberExt() {
ext()
member()
memberExt()
}
}
suspend fun RestrictedController.ext() {
ext()
member()
memberExt()
}
fun generate(c: suspend RestrictedController.() -> Unit) {}
fun runBlocking(x: suspend () -> Unit) {}
fun test() {
generate a@{
ext()
member()
memberExt()
this@a.ext()
this@a.member()
this@a.memberExt()
generate b@{
ext()
member()
memberExt()
this@a.ext()
this@a.member()
this@a.memberExt()
this@b.ext()
this@b.member()
this@b.memberExt()
}
runBlocking {
ext()
member()
memberExt()
this@a.ext()
this@a.member()
this@a.memberExt()
}
}
}
@@ -0,0 +1,73 @@
// !DIAGNOSTICS: -UNUSED_PARAMETER -SUSPENSION_CALL_MUST_BE_USED_AS_RETURN_VALUE
// COMMON_COROUTINES_TEST
interface SuperInterface
@COROUTINES_PACKAGE.RestrictsSuspension
open class RestrictedController : SuperInterface
class SubClass : RestrictedController()
suspend fun topLevel() {}
class A {
suspend fun member() {}
}
fun generate1(f: suspend SuperInterface.() -> Unit) {}
fun generate2(f: suspend RestrictedController.() -> Unit) {}
fun generate3(f: suspend SubClass.() -> Unit) {}
fun A.test() {
generate1 {
topLevel()
member()
with(A()) {
topLevel()
member()
}
}
generate2 {
topLevel()
member()
with(A()) {
topLevel()
member()
}
}
generate3 {
topLevel()
member()
with(A()) {
topLevel()
member()
}
}
suspend fun SuperInterface.fun1() {
topLevel()
member()
with(A()) {
topLevel()
member()
}
}
suspend fun RestrictedController.fun2() {
topLevel()
member()
with(A()) {
topLevel()
member()
}
}
suspend fun SubClass.fun3() {
topLevel()
member()
with(A()) {
topLevel()
member()
}
}
}

Some files were not shown because too many files have changed in this diff Show More