Hello, I encountered an unexpected behaviour it th...
# compiler
p
Hello, I encountered an unexpected behaviour it this code snippet:
Copy code
interface Command<T>
    
class TestUnitCommand : Command<Unit>

class TestIntCommand : Command<Int>
    
class TestStringCommand : Command<String>
    
class Result<T>
    
inline fun <reified T : Command<R>, reified R : Any> execute(crossinline block: suspend (T) -> R) {}

fun main() {
    execute<TestUnitCommand, Unit> { Result<Unit>() }        // OK
    execute<TestIntCommand, Int> { Result<Int>() }           // Error
    execute<TestStringCommand, String> { Result<String>() }  // Error
}
Why does it not error when
Command
generic parameter is
Unit
? Does it implicitly not return anything?
k
Yes, lambdas do implicitly return
Unit
, that's the point.
p
Okay, makes sense
k
(also for next time, these kinds of questions don't belong in #compiler, use #general or #getting-started instead)
p
Sorry, my bad