Report error about invalid if as expression on the if keyword

#KT-14633 Fixed
This commit is contained in:
Mikhail Zarechenskiy
2017-06-21 18:51:05 +03:00
parent e40c8fff05
commit 9847278699
16 changed files with 111 additions and 112 deletions
@@ -717,7 +717,7 @@ class ControlFlowInformationProvider private constructor(
val elseExpression = element.`else` val elseExpression = element.`else`
if (thenExpression == null || elseExpression == null) { if (thenExpression == null || elseExpression == null) {
trace.report(INVALID_IF_AS_EXPRESSION.on(element)) trace.report(INVALID_IF_AS_EXPRESSION.on(element.ifKeyword))
} }
else { else {
checkImplicitCastOnConditionalExpression(element) checkImplicitCastOnConditionalExpression(element)
@@ -776,7 +776,7 @@ public interface Errors {
DiagnosticFactory0<KtElement> SENSELESS_NULL_IN_WHEN = DiagnosticFactory0.create(WARNING); DiagnosticFactory0<KtElement> SENSELESS_NULL_IN_WHEN = DiagnosticFactory0.create(WARNING);
DiagnosticFactory0<KtIfExpression> INVALID_IF_AS_EXPRESSION = DiagnosticFactory0.create(ERROR); DiagnosticFactory0<PsiElement> INVALID_IF_AS_EXPRESSION = DiagnosticFactory0.create(ERROR);
// Nullability // Nullability
+53 -53
View File
@@ -15,15 +15,15 @@ fun test5(): Any = l@{ return@l }
fun test6(): Any = {<!RETURN_NOT_ALLOWED!>return<!> 1} fun test6(): Any = {<!RETURN_NOT_ALLOWED!>return<!> 1}
fun bbb() { fun bbb() {
return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!> return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>
} }
fun foo(<!UNUSED_PARAMETER!>expr<!>: StringBuilder): Int { fun foo(<!UNUSED_PARAMETER!>expr<!>: StringBuilder): Int {
val c = 'a' val c = 'a'
when(c) { when(c) {
0.toChar() -> throw Exception("zero") 0.toChar() -> throw Exception("zero")
else -> throw Exception("nonzero" + c) else -> throw Exception("nonzero" + c)
} }
} }
@@ -47,92 +47,92 @@ fun blockReturnValueTypeMatch() : Int {return 1}
fun blockReturnValueTypeMismatchUnit() : Int {return <!TYPE_MISMATCH!>Unit<!>} fun blockReturnValueTypeMismatchUnit() : Int {return <!TYPE_MISMATCH!>Unit<!>}
fun blockAndAndMismatch() : Int { fun blockAndAndMismatch() : Int {
<!UNUSED_EXPRESSION!>true && false<!> <!UNUSED_EXPRESSION!>true && false<!>
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun blockAndAndMismatch1() : Int { fun blockAndAndMismatch1() : Int {
return <!TYPE_MISMATCH!>true && false<!> return <!TYPE_MISMATCH!>true && false<!>
} }
fun blockAndAndMismatch2() : Int { fun blockAndAndMismatch2() : Int {
(return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>true<!>) && (return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>false<!>) (return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>true<!>) && (return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>false<!>)
} }
fun blockAndAndMismatch3() : Int { fun blockAndAndMismatch3() : Int {
<!UNUSED_EXPRESSION!>true || false<!> <!UNUSED_EXPRESSION!>true || false<!>
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun blockAndAndMismatch4() : Int { fun blockAndAndMismatch4() : Int {
return <!TYPE_MISMATCH!>true || false<!> return <!TYPE_MISMATCH!>true || false<!>
} }
fun blockAndAndMismatch5() : Int { fun blockAndAndMismatch5() : Int {
(return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>true<!>) || (return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>false<!>) (return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>true<!>) || (return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>false<!>)
} }
fun blockReturnValueTypeMatch1() : Int { fun blockReturnValueTypeMatch1() : Int {
return if (1 > 2) <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!> else <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!> return if (1 > 2) <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!> else <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!>
} }
fun blockReturnValueTypeMatch2() : Int { fun blockReturnValueTypeMatch2() : Int {
return <!TYPE_MISMATCH, INVALID_IF_AS_EXPRESSION!>if (1 > 2) 1<!> return <!TYPE_MISMATCH!><!INVALID_IF_AS_EXPRESSION!>if<!> (1 > 2) 1<!>
} }
fun blockReturnValueTypeMatch3() : Int { fun blockReturnValueTypeMatch3() : Int {
return <!TYPE_MISMATCH, INVALID_IF_AS_EXPRESSION!>if (1 > 2) else 1<!> return <!TYPE_MISMATCH!><!INVALID_IF_AS_EXPRESSION!>if<!> (1 > 2) else 1<!>
} }
fun blockReturnValueTypeMatch4() : Int { fun blockReturnValueTypeMatch4() : Int {
if (1 > 2) if (1 > 2)
return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!> return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!>
else return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!> else return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!>
} }
fun blockReturnValueTypeMatch5() : Int { fun blockReturnValueTypeMatch5() : Int {
if (1 > 2) if (1 > 2)
return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!> return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!>
return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!> return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!>
} }
fun blockReturnValueTypeMatch6() : Int { fun blockReturnValueTypeMatch6() : Int {
if (1 > 2) if (1 > 2)
else return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!> else return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!>
return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!> return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>2.0<!>
} }
fun blockReturnValueTypeMatch7() : Int { fun blockReturnValueTypeMatch7() : Int {
if (1 > 2) if (1 > 2)
<!UNUSED_EXPRESSION!>1.0<!> <!UNUSED_EXPRESSION!>1.0<!>
else <!UNUSED_EXPRESSION!>2.0<!> else <!UNUSED_EXPRESSION!>2.0<!>
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun blockReturnValueTypeMatch8() : Int { fun blockReturnValueTypeMatch8() : Int {
if (1 > 2) if (1 > 2)
<!UNUSED_EXPRESSION!>1.0<!> <!UNUSED_EXPRESSION!>1.0<!>
else <!UNUSED_EXPRESSION!>2.0<!> else <!UNUSED_EXPRESSION!>2.0<!>
return 1 return 1
} }
fun blockReturnValueTypeMatch9() : Int { fun blockReturnValueTypeMatch9() : Int {
if (1 > 2) if (1 > 2)
<!UNUSED_EXPRESSION!>1.0<!> <!UNUSED_EXPRESSION!>1.0<!>
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun blockReturnValueTypeMatch10() : Int { fun blockReturnValueTypeMatch10() : Int {
return <!TYPE_MISMATCH, INVALID_IF_AS_EXPRESSION!>if (1 > 2) return <!TYPE_MISMATCH!><!INVALID_IF_AS_EXPRESSION!>if<!> (1 > 2)
1<!> 1<!>
} }
fun blockReturnValueTypeMatch11() : Int { fun blockReturnValueTypeMatch11() : Int {
if (1 > 2) if (1 > 2)
else <!UNUSED_EXPRESSION!>1.0<!> else <!UNUSED_EXPRESSION!>1.0<!>
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun blockReturnValueTypeMatch12() : Int { fun blockReturnValueTypeMatch12() : Int {
if (1 > 2) if (1 > 2)
return 1 return 1
else return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!> else return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!>
} }
fun blockNoReturnIfValDeclaration(): Int { fun blockNoReturnIfValDeclaration(): Int {
val <!UNUSED_VARIABLE!>x<!> = 1 val <!UNUSED_VARIABLE!>x<!> = 1
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun blockNoReturnIfEmptyIf(): Int { fun blockNoReturnIfEmptyIf(): Int {
if (1 < 2) {} else {} if (1 < 2) {} else {}
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!> <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun blockNoReturnIfUnitInOneBranch(): Int { fun blockNoReturnIfUnitInOneBranch(): Int {
if (1 < 2) { if (1 < 2) {
return 1 return 1
} else {
if (3 < 4) {
} else { } else {
return 2 if (3 < 4) {
} else {
return 2
}
} }
} <!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
<!NO_RETURN_IN_FUNCTION_WITH_BLOCK_BODY!>}<!>
fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else <!TYPE_MISMATCH!>{}<!> fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else <!TYPE_MISMATCH!>{}<!>
fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else 2 fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) <!TYPE_MISMATCH!>{}<!> else 2
@@ -145,7 +145,7 @@ fun illegalConstantBlock(): String {
return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!> return <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1<!>
} }
fun illegalIfBody(): Int = fun illegalIfBody(): Int =
if (1 < 2) <!CONSTANT_EXPECTED_TYPE_MISMATCH!>'a'<!> else { <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!> } if (1 < 2) <!CONSTANT_EXPECTED_TYPE_MISMATCH!>'a'<!> else { <!CONSTANT_EXPECTED_TYPE_MISMATCH!>1.0<!> }
fun illegalIfBlock(): Boolean { fun illegalIfBlock(): Boolean {
if (1 < 2) if (1 < 2)
return false return false
@@ -166,7 +166,7 @@ fun f1(): Int = if (1 < 2) 1 else returnNothing()
public fun f2() = 1 public fun f2() = 1
class B() { class B() {
protected fun f() = "ss" protected fun f() = "ss"
} }
fun testFunctionLiterals() { fun testFunctionLiterals() {
@@ -4,13 +4,13 @@ fun test() {
if (false); if (false);
if (true); if (true);
val x = <!INVALID_IF_AS_EXPRESSION!>if (false)<!>; val x = <!INVALID_IF_AS_EXPRESSION!>if<!> (false);
foo(x) foo(x)
val y: Unit = <!INVALID_IF_AS_EXPRESSION!>if (false)<!>; val y: Unit = <!INVALID_IF_AS_EXPRESSION!>if<!> (false);
foo(y) foo(y)
foo({if (1==1);}()) foo({if (1==1);}())
return <!INVALID_IF_AS_EXPRESSION!>if (true)<!>; return <!INVALID_IF_AS_EXPRESSION!>if<!> (true);
} }
@@ -8,23 +8,23 @@ fun testMixedIfAndWhen() =
if (true) if (true)
when { when {
true -> if (true) <!IMPLICIT_CAST_TO_ANY!>42<!> true -> if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
else <!IMPLICIT_CAST_TO_ANY!>1<!> else <!IMPLICIT_CAST_TO_ANY!>1<!>
true -> if (true) <!IMPLICIT_CAST_TO_ANY!>42<!> true -> if (true) <!IMPLICIT_CAST_TO_ANY!>42<!>
else <!IMPLICIT_CAST_TO_ANY!>println()<!> else <!IMPLICIT_CAST_TO_ANY!>println()<!>
else -> <!INVALID_IF_AS_EXPRESSION!>if (true) <!IMPLICIT_CAST_TO_ANY!>println()<!><!> else -> <!INVALID_IF_AS_EXPRESSION!>if<!> (true) <!IMPLICIT_CAST_TO_ANY!>println()<!>
} }
else <!IMPLICIT_CAST_TO_ANY!>println()<!> else <!IMPLICIT_CAST_TO_ANY!>println()<!>
fun testWrappedExpressions() = fun testWrappedExpressions() =
if (true) { if (true) {
println() println()
<!INVALID_IF_AS_EXPRESSION!>if (true) { <!INVALID_IF_AS_EXPRESSION!>if<!> (true) {
println() println()
if (true) { if (true) {
<!IMPLICIT_CAST_TO_ANY!>println()<!> <!IMPLICIT_CAST_TO_ANY!>println()<!>
} }
else <!IMPLICIT_CAST_TO_ANY!>{}<!> else <!IMPLICIT_CAST_TO_ANY!>{}<!>
}<!> }
} }
else { else {
(((<!IMPLICIT_CAST_TO_ANY!>((42)) + 1<!>))) (((<!IMPLICIT_CAST_TO_ANY!>((42)) + 1<!>)))
@@ -10,13 +10,13 @@ val mlist = MList()
fun work() {} fun work() {}
val xx1 = <!INVALID_IF_AS_EXPRESSION!>if (true) 42<!> val xx1 = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
val xx2: Unit = <!INVALID_IF_AS_EXPRESSION!>if (true) 42<!> val xx2: Unit = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
val xx3 = idAny(<!INVALID_IF_AS_EXPRESSION!>if (true) 42<!>) val xx3 = idAny(<!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42)
val xx4 = id(<!INVALID_IF_AS_EXPRESSION!>if (true) 42<!>) val xx4 = id(<!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42)
val xx5 = idUnit(<!INVALID_IF_AS_EXPRESSION!>if (true) 42<!>) val xx5 = idUnit(<!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42)
val xx6 = null ?: <!INVALID_IF_AS_EXPRESSION!>if (true) 42<!> val xx6 = null ?: <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
val xx7 = "" + <!INVALID_IF_AS_EXPRESSION!>if (true) 42<!> val xx7 = "" + <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
val wxx1 = <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 } val wxx1 = <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
val wxx2: Unit = <!NO_ELSE_IN_WHEN!>when<!> { true -> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!> } val wxx2: Unit = <!NO_ELSE_IN_WHEN!>when<!> { true -> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!> }
@@ -40,12 +40,12 @@ val ufn4: () -> Unit = { when { true -> <!UNUSED_EXPRESSION!>42<!> } }
val ufn5: () -> Unit = { when { true -> mlist.add() } } val ufn5: () -> Unit = { when { true -> mlist.add() } }
val ufn6: () -> Unit = { when { true -> work() } } val ufn6: () -> Unit = { when { true -> work() } }
fun f1() = <!INVALID_IF_AS_EXPRESSION!>if (true) work()<!> fun f1() = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) work()
fun f2() = <!INVALID_IF_AS_EXPRESSION!>if (true) mlist.add()<!> fun f2() = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) mlist.add()
fun f3() = <!INVALID_IF_AS_EXPRESSION!>if (true) 42<!> fun f3() = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
fun f4(): Unit = <!INVALID_IF_AS_EXPRESSION!>if (true) work()<!> fun f4(): Unit = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) work()
fun f5(): Unit = <!INVALID_IF_AS_EXPRESSION!>if (true) mlist.add()<!> fun f5(): Unit = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) mlist.add()
fun f6(): Unit = <!INVALID_IF_AS_EXPRESSION!>if (true) 42<!> fun f6(): Unit = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
fun g1() = <!NO_ELSE_IN_WHEN!>when<!> { true -> work() } fun g1() = <!NO_ELSE_IN_WHEN!>when<!> { true -> work() }
fun g2() = <!NO_ELSE_IN_WHEN!>when<!> { true -> mlist.add() } fun g2() = <!NO_ELSE_IN_WHEN!>when<!> { true -> mlist.add() }
fun g3() = <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 } fun g3() = <!NO_ELSE_IN_WHEN!>when<!> { true -> 42 }
@@ -54,7 +54,7 @@ fun g5(): Unit = <!NO_ELSE_IN_WHEN!>when<!> { true -> <!TYPE_MISMATCH!>mlist.add
fun g6(): Unit = <!NO_ELSE_IN_WHEN!>when<!> { true -> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!> } fun g6(): Unit = <!NO_ELSE_IN_WHEN!>when<!> { true -> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>42<!> }
fun foo1(x: String?) { fun foo1(x: String?) {
"" + <!INVALID_IF_AS_EXPRESSION!>if (true) 42<!> "" + <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 42
w@while (true) { w@while (true) {
x ?: if (true) break x ?: if (true) break
x ?: when { true -> break@w } x ?: when { true -> break@w }
@@ -2,9 +2,9 @@
fun example() { fun example() {
val a = if (true) true else false val a = if (true) true else false
val b = <!INVALID_IF_AS_EXPRESSION!>if (true) else false<!> val b = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) else false
val c = <!INVALID_IF_AS_EXPRESSION!>if (true) true<!> val c = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) true
val d = <!INVALID_IF_AS_EXPRESSION!>if (true) true else<!>; val d = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) true else;
val e = if (true) <!IMPLICIT_CAST_TO_ANY!>{}<!> else <!IMPLICIT_CAST_TO_ANY!>false<!> val e = if (true) <!IMPLICIT_CAST_TO_ANY!>{}<!> else <!IMPLICIT_CAST_TO_ANY!>false<!>
val f = if (true) <!IMPLICIT_CAST_TO_ANY!>true<!> else <!IMPLICIT_CAST_TO_ANY!>{}<!> val f = if (true) <!IMPLICIT_CAST_TO_ANY!>true<!> else <!IMPLICIT_CAST_TO_ANY!>{}<!>
@@ -26,7 +26,7 @@ fun example() {
}() }()
fun t(): Boolean { fun t(): Boolean {
return <!TYPE_MISMATCH, INVALID_IF_AS_EXPRESSION!>if (true) true<!> return <!TYPE_MISMATCH!><!INVALID_IF_AS_EXPRESSION!>if<!> (true) true<!>
} }
return if (true) <!CONSTANT_EXPECTED_TYPE_MISMATCH!>true<!> else {} return if (true) <!CONSTANT_EXPECTED_TYPE_MISMATCH!>true<!> else {}
@@ -1,7 +1,7 @@
fun test1() { fun test1() {
run { run {
if (true) { if (true) {
<!INVALID_IF_AS_EXPRESSION!>if (true) {}<!> <!INVALID_IF_AS_EXPRESSION!>if<!> (true) {}
} }
else { else {
1 1
@@ -4,7 +4,7 @@ fun test(a: Boolean, b: Boolean): Int {
return if(a) { return if(a) {
1 1
} else { } else {
<!TYPE_MISMATCH, INVALID_IF_AS_EXPRESSION!>if (b) { <!TYPE_MISMATCH!><!INVALID_IF_AS_EXPRESSION!>if<!> (b) {
3 3
}<!> }<!>
} }
@@ -95,21 +95,21 @@ fun testImplicitCoercion() {
var <!UNUSED_VARIABLE!>u<!> = when(d) { var <!UNUSED_VARIABLE!>u<!> = when(d) {
3 -> { 3 -> {
<!IMPLICIT_CAST_TO_ANY!><!UNUSED_VALUE!>z =<!> 34<!> <!IMPLICIT_CAST_TO_ANY!><!UNUSED_VALUE!>z =<!> 34<!>
} }
else -> <!UNUSED_CHANGED_VALUE, IMPLICIT_CAST_TO_ANY!>z--<!> else -> <!UNUSED_CHANGED_VALUE, IMPLICIT_CAST_TO_ANY!>z--<!>
} }
var <!UNUSED_VARIABLE!>iff<!> = <!INVALID_IF_AS_EXPRESSION!>if (true) { var <!UNUSED_VARIABLE!>iff<!> = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) {
<!UNUSED_VALUE!>z =<!> 34 <!UNUSED_VALUE!>z =<!> 34
}<!> }
val <!UNUSED_VARIABLE!>g<!> = <!INVALID_IF_AS_EXPRESSION!>if (true) 4<!> val <!UNUSED_VARIABLE!>g<!> = <!INVALID_IF_AS_EXPRESSION!>if<!> (true) 4
val <!UNUSED_VARIABLE!>h<!> = if (false) <!IMPLICIT_CAST_TO_ANY!>4<!> else <!IMPLICIT_CAST_TO_ANY!>{}<!> val <!UNUSED_VARIABLE!>h<!> = if (false) <!IMPLICIT_CAST_TO_ANY!>4<!> else <!IMPLICIT_CAST_TO_ANY!>{}<!>
bar(if (true) { bar(if (true) {
<!CONSTANT_EXPECTED_TYPE_MISMATCH!>4<!> <!CONSTANT_EXPECTED_TYPE_MISMATCH!>4<!>
} }
else { else {
<!UNUSED_VALUE!>z =<!> 342 <!UNUSED_VALUE!>z =<!> 342
}) })
} }
+2 -2
View File
@@ -18,7 +18,7 @@ fun f3(s: Number?) {
} }
fun f4(s: Int?) { fun f4(s: Int?) {
var u = <!INVALID_IF_AS_EXPRESSION!>if (s!! == 42)<!>; var u = <!INVALID_IF_AS_EXPRESSION!>if<!> (s!! == 42);
if (u == Unit) u = <!INVALID_IF_AS_EXPRESSION!>if (s == 239)<!>; if (u == Unit) u = <!INVALID_IF_AS_EXPRESSION!>if<!> (s == 239);
return u return u
} }
@@ -10,20 +10,20 @@ fun test() {
foo({ <!EXPECTED_TYPE_MISMATCH!>fun named3() = 1<!> }) foo({ <!EXPECTED_TYPE_MISMATCH!>fun named3() = 1<!> })
val x1 = val x1 =
if (1 == 1) <!INVALID_IF_AS_EXPRESSION!>if<!> (1 == 1)
// TODO: Diagnostic content could be better // TODO: Diagnostic content could be better
<!SYNTAX!><!>fun named4(): Int {return 1} <!SYNTAX!><!>fun named4(): Int {return 1}
<!SYNTAX!>else<!> <!SYNTAX!>else<!>
fun named5() = 1 fun named5() = 1
val x2 = val x2 =
if (1 == 1) { <!INVALID_IF_AS_EXPRESSION!>if<!> (1 == 1) {
fun named6(): Int { fun named6(): Int {
return 1 return 1
} }
} }
else else
<!SYNTAX!><!>fun named7() = 1 <!SYNTAX!><!>fun named7() = 1
val x3 = when (1) { val x3 = when (1) {
0 -> <!EXPECTED_TYPE_MISMATCH!>fun named8(): Int {return 1}<!> 0 -> <!EXPECTED_TYPE_MISMATCH!>fun named8(): Int {return 1}<!>
@@ -2,7 +2,7 @@ val flag = true
// type of a was checked by txt // type of a was checked by txt
val a/*: () -> Any*/ = l@ { val a/*: () -> Any*/ = l@ {
<!INVALID_IF_AS_EXPRESSION!>if (flag) return@l 4<!> <!INVALID_IF_AS_EXPRESSION!>if<!> (flag) return@l 4
} }
val b/*: () -> Int */ = l@ { val b/*: () -> Int */ = l@ {
@@ -1,7 +1,7 @@
val flag = true val flag = true
val a: () -> Int = l@ { val a: () -> Int = l@ {
<!TYPE_MISMATCH, INVALID_IF_AS_EXPRESSION!>if (flag) return@l 4<!> <!TYPE_MISMATCH!><!INVALID_IF_AS_EXPRESSION!>if<!> (flag) return@l 4<!>
} }
val b: () -> Unit = l@ { val b: () -> Unit = l@ {
@@ -9,7 +9,7 @@ val b: () -> Unit = l@ {
} }
val c: () -> Any = l@ { val c: () -> Any = l@ {
<!INVALID_IF_AS_EXPRESSION!>if (flag) return@l 4<!> <!INVALID_IF_AS_EXPRESSION!>if<!> (flag) return@l 4
} }
val d: () -> Int = l@ { val d: () -> Int = l@ {
@@ -14,7 +14,7 @@ fun test1(word: String) =
fun test2(word: String) = fun test2(word: String) =
run { run {
if (word.length > 4) { if (word.length > 4) {
<!INVALID_IF_AS_EXPRESSION!>if (word.startsWith("a")) <!IMPLICIT_CAST_TO_ANY!>longWords++<!><!> <!INVALID_IF_AS_EXPRESSION!>if<!> (word.startsWith("a")) <!IMPLICIT_CAST_TO_ANY!>longWords++<!>
} }
else { else {
<!IMPLICIT_CAST_TO_ANY!>smallWords.add(word)<!> <!IMPLICIT_CAST_TO_ANY!>smallWords.add(word)<!>
+3 -4
View File
@@ -65,10 +65,10 @@ fun blockReturnValueTypeMatch1() : Int {
return if (1 > 2) <error>1.0</error> else <error>2.0</error> return if (1 > 2) <error>1.0</error> else <error>2.0</error>
} }
fun blockReturnValueTypeMatch2() : Int { fun blockReturnValueTypeMatch2() : Int {
return <error>if (1 > 2) 1</error> return <error><error>if</error> (1 > 2) 1</error>
} }
fun blockReturnValueTypeMatch3() : Int { fun blockReturnValueTypeMatch3() : Int {
return <error>if (1 > 2) else 1</error> return <error><error>if</error> (1 > 2) else 1</error>
} }
fun blockReturnValueTypeMatch4() : Int { fun blockReturnValueTypeMatch4() : Int {
if (1 > 2) if (1 > 2)
@@ -101,8 +101,7 @@ fun blockReturnValueTypeMatch9() : Int {
<warning>1.0</warning> <warning>1.0</warning>
<error>}</error> <error>}</error>
fun blockReturnValueTypeMatch10() : Int { fun blockReturnValueTypeMatch10() : Int {
return <error>if (1 > 2) return <error><error>if</error> (1 > 2) 1</error>
1</error>
} }
fun blockReturnValueTypeMatch11() : Int { fun blockReturnValueTypeMatch11() : Int {
if (1 > 2) if (1 > 2)