KT-234 Force when() expressions to have an 'else' branch

KT-973 Unreachable code
This commit is contained in:
svtk
2012-01-18 13:31:42 +04:00
parent 94e3cc9976
commit becd713111
23 changed files with 175 additions and 50 deletions
+1 -1
View File
@@ -18,9 +18,9 @@ fun testUnresolved() {
when(<error>a</error>) {
is Int -> <error>a</error>
is String -> <error>a</error>
else -> <error>a</error>
}
//TODO
for (j in <error>collection</error>) {
var i: Int = j
i += 1
+5 -4
View File
@@ -4,7 +4,6 @@ fun foo() : Int {
val s = ""
val x = 1
when (x) {
is * -> 1
is <error>String</error> -> 1
!is Int -> 1
is Any? -> 1
@@ -16,7 +15,7 @@ fun foo() : Int {
// Commented for KT-621 .<!error>a</!error> -> 1
// Commented for KT-621 .equals(1).<!error>a</!error> -> 1
// Commented for KT-621 <!warning>?.</!warning>equals(1) -> 1
else -> 1
is * -> 1
}
// Commented for KT-621
@@ -39,6 +38,7 @@ fun test() {
x -> 1
is 1 -> 1
is <error>#(1, 1)</error> -> 1
else -> 1
}
val z = #(1, 1)
@@ -51,11 +51,12 @@ fun test() {
is <error>#(1, "1", *)</error> -> 1
is boo #(1, <error>"a"</error>, *) -> 1
is boo <error>#(1, *)</error> -> 1
else -> 1
}
when (z) {
<error>else -> 1</error>
#(1, 1) -> 2
<error>else</error> -> 1
<error>#(1, 1) -> 2</error>
}
when (z) {
+3 -1
View File
@@ -154,11 +154,13 @@ fun toInt(i: Int?): Int = if (i != null) <info descr="Automatically cast to Int"
fun illegalWhenBody(a: Any): Int = when(a) {
is Int -> <info descr="Automatically cast to Int">a</info>
is String -> <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any but Int was expected">a</error>
else -> 1
}
fun illegalWhenBlock(a: Any): Int {
when(a) {
is Int -> return <info descr="Automatically cast to Int">a</info>
is String -> return <error descr="[TYPE_MISMATCH] Type mismatch: inferred type is Any but Int was expected">a</error>
else -> return 1
}
}
fun declarations(a: Any?) {
@@ -221,7 +223,7 @@ fun mergeAutocasts(a: Any?) {
if (a is Int || a is String) {
a.<error descr="Unresolved reference: compareTo">compareTo</error>("")
}
when (a) {
<error>when</error> (a) {
is String, is Any -> a.<error descr="Unresolved reference: compareTo">compareTo</error>("")
}
if (a is String && a is Any) {