diff --git a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt index 6f9a33f81b9..2c5cd06c435 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/cfg/ControlFlowInformationProvider.kt @@ -717,7 +717,7 @@ class ControlFlowInformationProvider private constructor( val elseExpression = element.`else` if (thenExpression == null || elseExpression == null) { - trace.report(INVALID_IF_AS_EXPRESSION.on(element)) + trace.report(INVALID_IF_AS_EXPRESSION.on(element.ifKeyword)) } else { checkImplicitCastOnConditionalExpression(element) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java index 70c1ae5ab7a..f5c4a94707a 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/diagnostics/Errors.java @@ -776,7 +776,7 @@ public interface Errors { DiagnosticFactory0 SENSELESS_NULL_IN_WHEN = DiagnosticFactory0.create(WARNING); - DiagnosticFactory0 INVALID_IF_AS_EXPRESSION = DiagnosticFactory0.create(ERROR); + DiagnosticFactory0 INVALID_IF_AS_EXPRESSION = DiagnosticFactory0.create(ERROR); // Nullability diff --git a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt index 19fd0991854..7a6a50f89f1 100644 --- a/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt +++ b/compiler/testData/diagnostics/tests/FunctionReturnTypes.kt @@ -15,15 +15,15 @@ fun test5(): Any = l@{ return@l } fun test6(): Any = {return 1} fun bbb() { - return 1 + return 1 } fun foo(expr: StringBuilder): Int { - val c = 'a' - when(c) { - 0.toChar() -> throw Exception("zero") - else -> throw Exception("nonzero" + c) - } + val c = 'a' + when(c) { + 0.toChar() -> throw Exception("zero") + else -> throw Exception("nonzero" + c) + } } @@ -47,92 +47,92 @@ fun blockReturnValueTypeMatch() : Int {return 1} fun blockReturnValueTypeMismatchUnit() : Int {return Unit} fun blockAndAndMismatch() : Int { - true && false -} + true && false + } fun blockAndAndMismatch1() : Int { - return true && false + return true && false } fun blockAndAndMismatch2() : Int { - (return true) && (return false) + (return true) && (return false) } fun blockAndAndMismatch3() : Int { - true || false -} + true || false + } fun blockAndAndMismatch4() : Int { - return true || false + return true || false } fun blockAndAndMismatch5() : Int { - (return true) || (return false) + (return true) || (return false) } fun blockReturnValueTypeMatch1() : Int { - return if (1 > 2) 1.0 else 2.0 + return if (1 > 2) 1.0 else 2.0 } fun blockReturnValueTypeMatch2() : Int { - return if (1 > 2) 1 + return if (1 > 2) 1 } fun blockReturnValueTypeMatch3() : Int { - return if (1 > 2) else 1 + return if (1 > 2) else 1 } fun blockReturnValueTypeMatch4() : Int { - if (1 > 2) - return 1.0 - else return 2.0 + if (1 > 2) + return 1.0 + else return 2.0 } fun blockReturnValueTypeMatch5() : Int { - if (1 > 2) - return 1.0 - return 2.0 + if (1 > 2) + return 1.0 + return 2.0 } fun blockReturnValueTypeMatch6() : Int { - if (1 > 2) + if (1 > 2) else return 1.0 - return 2.0 + return 2.0 } fun blockReturnValueTypeMatch7() : Int { - if (1 > 2) + if (1 > 2) 1.0 - else 2.0 -} + else 2.0 + } fun blockReturnValueTypeMatch8() : Int { - if (1 > 2) + if (1 > 2) 1.0 - else 2.0 - return 1 + else 2.0 + return 1 } fun blockReturnValueTypeMatch9() : Int { - if (1 > 2) + if (1 > 2) 1.0 -} + } fun blockReturnValueTypeMatch10() : Int { - return if (1 > 2) + return if (1 > 2) 1 } fun blockReturnValueTypeMatch11() : Int { - if (1 > 2) - else 1.0 -} + if (1 > 2) + else 1.0 + } fun blockReturnValueTypeMatch12() : Int { - if (1 > 2) - return 1 - else return 1.0 + if (1 > 2) + return 1 + else return 1.0 } fun blockNoReturnIfValDeclaration(): Int { - val x = 1 -} + val x = 1 + } fun blockNoReturnIfEmptyIf(): Int { - if (1 < 2) {} else {} -} + if (1 < 2) {} else {} + } fun blockNoReturnIfUnitInOneBranch(): Int { - if (1 < 2) { - return 1 - } else { - if (3 < 4) { + if (1 < 2) { + return 1 } else { - return 2 + if (3 < 4) { + } else { + return 2 + } } - } -} + } fun nonBlockReturnIfEmptyIf(): Int = if (1 < 2) {} else {} fun nonBlockNoReturnIfUnitInOneBranch(): Int = if (1 < 2) {} else 2 @@ -145,7 +145,7 @@ fun illegalConstantBlock(): String { return 1 } fun illegalIfBody(): Int = - if (1 < 2) 'a' else { 1.0 } + if (1 < 2) 'a' else { 1.0 } fun illegalIfBlock(): Boolean { if (1 < 2) return false @@ -166,7 +166,7 @@ fun f1(): Int = if (1 < 2) 1 else returnNothing() public fun f2() = 1 class B() { - protected fun f() = "ss" + protected fun f() = "ss" } fun testFunctionLiterals() { diff --git a/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt b/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt index bf67e7d5a44..13ce5412108 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/emptyIf.kt @@ -4,13 +4,13 @@ fun test() { if (false); if (true); - val x = if (false); + val x = if (false); foo(x) - val y: Unit = if (false); + val y: Unit = if (false); foo(y) foo({if (1==1);}()) - return if (true); + return if (true); } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifWhenToAnyComplexExpressions.kt b/compiler/testData/diagnostics/tests/controlStructures/ifWhenToAnyComplexExpressions.kt index fd2c21c06bf..1ddb4e9eefc 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/ifWhenToAnyComplexExpressions.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/ifWhenToAnyComplexExpressions.kt @@ -8,23 +8,23 @@ fun testMixedIfAndWhen() = if (true) when { true -> if (true) 42 - else 1 - true -> if (true) 42 - else println() - else -> if (true) println() + else 1 + true -> if (true) 42 + else println() + else -> if (true) println() } else println() fun testWrappedExpressions() = if (true) { println() - if (true) { + if (true) { println() if (true) { println() } else {} - } + } } else { (((((42)) + 1))) diff --git a/compiler/testData/diagnostics/tests/controlStructures/ifWhenWithoutElse.kt b/compiler/testData/diagnostics/tests/controlStructures/ifWhenWithoutElse.kt index b4b093a65ea..d3de167ac60 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/ifWhenWithoutElse.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/ifWhenWithoutElse.kt @@ -10,13 +10,13 @@ val mlist = MList() fun work() {} -val xx1 = if (true) 42 -val xx2: Unit = if (true) 42 -val xx3 = idAny(if (true) 42) -val xx4 = id(if (true) 42) -val xx5 = idUnit(if (true) 42) -val xx6 = null ?: if (true) 42 -val xx7 = "" + if (true) 42 +val xx1 = if (true) 42 +val xx2: Unit = if (true) 42 +val xx3 = idAny(if (true) 42) +val xx4 = id(if (true) 42) +val xx5 = idUnit(if (true) 42) +val xx6 = null ?: if (true) 42 +val xx7 = "" + if (true) 42 val wxx1 = when { true -> 42 } val wxx2: Unit = when { true -> 42 } @@ -40,12 +40,12 @@ val ufn4: () -> Unit = { when { true -> 42 } } val ufn5: () -> Unit = { when { true -> mlist.add() } } val ufn6: () -> Unit = { when { true -> work() } } -fun f1() = if (true) work() -fun f2() = if (true) mlist.add() -fun f3() = if (true) 42 -fun f4(): Unit = if (true) work() -fun f5(): Unit = if (true) mlist.add() -fun f6(): Unit = if (true) 42 +fun f1() = if (true) work() +fun f2() = if (true) mlist.add() +fun f3() = if (true) 42 +fun f4(): Unit = if (true) work() +fun f5(): Unit = if (true) mlist.add() +fun f6(): Unit = if (true) 42 fun g1() = when { true -> work() } fun g2() = when { true -> mlist.add() } fun g3() = when { true -> 42 } @@ -54,7 +54,7 @@ fun g5(): Unit = when { true -> mlist.add fun g6(): Unit = when { true -> 42 } fun foo1(x: String?) { - "" + if (true) 42 + "" + if (true) 42 w@while (true) { x ?: if (true) break x ?: when { true -> break@w } diff --git a/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.kt b/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.kt index f7b6180580d..e47e1abb44a 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/improperElseInExpression.kt @@ -2,9 +2,9 @@ fun example() { val a = if (true) true else false - val b = if (true) else false - val c = if (true) true - val d = if (true) true else; + val b = if (true) else false + val c = if (true) true + val d = if (true) true else; val e = if (true) {} else false val f = if (true) true else {} @@ -26,7 +26,7 @@ fun example() { }() fun t(): Boolean { - return if (true) true + return if (true) true } return if (true) true else {} diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt10322.kt b/compiler/testData/diagnostics/tests/controlStructures/kt10322.kt index 68bd3148541..75498130867 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt10322.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt10322.kt @@ -1,7 +1,7 @@ fun test1() { run { if (true) { - if (true) {} + if (true) {} } else { 1 diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt b/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt index 92239f7037d..422cabb622d 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt4310.kt @@ -4,7 +4,7 @@ fun test(a: Boolean, b: Boolean): Int { return if(a) { 1 } else { - if (b) { + if (b) { 3 } } diff --git a/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt b/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt index 447b413ade9..d35bb352c1b 100644 --- a/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt +++ b/compiler/testData/diagnostics/tests/controlStructures/kt770.kt351.kt735_StatementType.kt @@ -95,21 +95,21 @@ fun testImplicitCoercion() { var u = when(d) { 3 -> { - z = 34 - } + z = 34 + } else -> z-- } - var iff = if (true) { + var iff = if (true) { z = 34 - } - val g = if (true) 4 + } + val g = if (true) 4 val h = if (false) 4 else {} bar(if (true) { 4 } - else { + else { z = 342 }) } diff --git a/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.kt b/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.kt index e54c9a7ae6c..3d616d95e36 100644 --- a/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.kt +++ b/compiler/testData/diagnostics/tests/dataFlow/EmptyIf.kt @@ -18,7 +18,7 @@ fun f3(s: Number?) { } fun f4(s: Int?) { - var u = if (s!! == 42); - if (u == Unit) u = if (s == 239); + var u = if (s!! == 42); + if (u == Unit) u = if (s == 239); return u } \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt index c7da3add29b..f98be643f81 100644 --- a/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt +++ b/compiler/testData/diagnostics/tests/declarationChecks/namedFunAsLastExpressionInBlock.kt @@ -10,20 +10,20 @@ fun test() { foo({ fun named3() = 1 }) val x1 = - if (1 == 1) - // TODO: Diagnostic content could be better - fun named4(): Int {return 1} - else - fun named5() = 1 + if (1 == 1) + // TODO: Diagnostic content could be better + fun named4(): Int {return 1} + else + fun named5() = 1 val x2 = - if (1 == 1) { - fun named6(): Int { - return 1 - } - } - else - fun named7() = 1 + if (1 == 1) { + fun named6(): Int { + return 1 + } + } + else + fun named7() = 1 val x3 = when (1) { 0 -> fun named8(): Int {return 1} diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.kt index 7d02a8b3433..79750663a38 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElse.kt @@ -2,7 +2,7 @@ val flag = true // type of a was checked by txt val a/*: () -> Any*/ = l@ { - if (flag) return@l 4 + if (flag) return@l 4 } val b/*: () -> Int */ = l@ { diff --git a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.kt b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.kt index ef1c77c23ba..a300099a0c0 100644 --- a/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.kt +++ b/compiler/testData/diagnostics/tests/functionLiterals/return/IfWithoutElseWithExplicitType.kt @@ -1,7 +1,7 @@ val flag = true val a: () -> Int = l@ { - if (flag) return@l 4 + if (flag) return@l 4 } val b: () -> Unit = l@ { @@ -9,7 +9,7 @@ val b: () -> Unit = l@ { } val c: () -> Any = l@ { - if (flag) return@l 4 + if (flag) return@l 4 } val d: () -> Int = l@ { diff --git a/compiler/testData/diagnostics/testsWithStdLib/implicitCastToAny.kt b/compiler/testData/diagnostics/testsWithStdLib/implicitCastToAny.kt index f684795dbf8..2770e74780c 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/implicitCastToAny.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/implicitCastToAny.kt @@ -14,7 +14,7 @@ fun test1(word: String) = fun test2(word: String) = run { if (word.length > 4) { - if (word.startsWith("a")) longWords++ + if (word.startsWith("a")) longWords++ } else { smallWords.add(word) diff --git a/idea/testData/checker/FunctionReturnTypes.kt b/idea/testData/checker/FunctionReturnTypes.kt index 8a969b6d8b2..9be498b02b5 100644 --- a/idea/testData/checker/FunctionReturnTypes.kt +++ b/idea/testData/checker/FunctionReturnTypes.kt @@ -65,10 +65,10 @@ fun blockReturnValueTypeMatch1() : Int { return if (1 > 2) 1.0 else 2.0 } fun blockReturnValueTypeMatch2() : Int { - return if (1 > 2) 1 + return if (1 > 2) 1 } fun blockReturnValueTypeMatch3() : Int { - return if (1 > 2) else 1 + return if (1 > 2) else 1 } fun blockReturnValueTypeMatch4() : Int { if (1 > 2) @@ -101,8 +101,7 @@ fun blockReturnValueTypeMatch9() : Int { 1.0 } fun blockReturnValueTypeMatch10() : Int { - return if (1 > 2) - 1 + return if (1 > 2) 1 } fun blockReturnValueTypeMatch11() : Int { if (1 > 2)