Are these errors expected? They seem quite counter...
# compiler
f
Are these errors expected? They seem quite counter-intuitive to me 😕 Playground: https://pl.kotl.in/w38CtHeCP
y
its because suspend here is actually a function which takes a lambda with no arguments. This works:
Copy code
fun main() {
    var myList: List<suspend (Int) -> Int>
    myList = listOf(suspend { n: Int -> n })
    myList = listOf(suspend { n: Int -> n})
    myList = listOf(suspend { it })
    //myList = listOf({ n: Int -> n })
    myList = listOf({ n -> n })
    myList = listOf({ it })
}

fun <T, R> suspend(block: suspend (T) -> R) = block
except that this convention is deprecated now, probably for the better, and so instead you can surround the lambda in parens, or better just rename that fun suspend to suspendLambda or something
thank you color 1
e
yep, even though it looks like a keyword it's actually https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/suspend.html
thank you color 1
this should be fixed in some future version of Kotlin https://youtrack.jetbrains.com/issue/KT-22765
f
Ahh, makes sense, thanks! What still may be confusing is why
Copy code
// Explicit type -> doesn't work
myList = listOf({ n: Int -> n })
// Implicit type -> works
myList = listOf({ n -> n })
🤔