Last active
October 12, 2016 07:39
-
-
Save kmizu/81cd2a2940630fcab19feba1ba3e6a28 to your computer and use it in GitHub Desktop.
A question about relation between Kotlin's Unit and other types
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fun foo(): Unit = run<Unit> { | |
1 + 1 | |
} | |
fun add(x: Int, y: Int): Int = run { | |
x + y | |
} | |
fun main(args: Array<String>) { | |
/* | |
val x: Unit = add(1, 2) | |
error: type mismatch: inferred type is kotlin.Int but kotlin.Unit was expected | |
val x: Unit = add(1, 2) | |
^ | |
*/ | |
/* | |
It seems that implicit conversion from T to Unit is not defined. | |
Then, why does foo() function compiles ? | |
*/ | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment