Deprecate simplification of complex boolean constant expressions in whens and loops
^KT-39883 In Progress
This commit is contained in:
committed by
teamcityserver
parent
8a2e0cedf9
commit
05883afc0a
@@ -1,18 +0,0 @@
|
||||
/*
|
||||
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
|
||||
*
|
||||
* SPEC VERSION: 0.1-313
|
||||
* PRIMARY LINKS: expressions, when-expression -> paragraph 5 -> sentence 1
|
||||
* expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 3
|
||||
* expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 4
|
||||
* expressions, when-expression, exhaustive-when-expressions -> paragraph 2 -> sentence 5
|
||||
*/
|
||||
|
||||
// See also: KT-3743
|
||||
fun foo(arg: Boolean): String {
|
||||
// Must be exhaustive
|
||||
return <!NO_ELSE_IN_WHEN!>when<!>(arg) {
|
||||
2 == 2 -> "truth"
|
||||
2 == 1 -> "falsehood"
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +ProhibitSimplificationOfNonTrivialConstBooleanExpressions
|
||||
/*
|
||||
* KOTLIN DIAGNOSTICS SPEC TEST (NEGATIVE)
|
||||
*
|
||||
@@ -11,7 +13,7 @@
|
||||
// See also: KT-3743
|
||||
fun foo(arg: Boolean): String {
|
||||
// Must be exhaustive
|
||||
return when(arg) {
|
||||
return <!NO_ELSE_IN_WHEN!>when<!>(arg) {
|
||||
2 == 2 -> "truth"
|
||||
2 == 1 -> "falsehood"
|
||||
}
|
||||
|
||||
+32
@@ -0,0 +1,32 @@
|
||||
// FIR_IDENTICAL
|
||||
// !LANGUAGE: +ProhibitSimplificationOfNonTrivialConstBooleanExpressions
|
||||
// ISSUE: KT-39883
|
||||
|
||||
// Should always work
|
||||
fun test_0(b: Boolean): String = when (b) {
|
||||
true -> "true"
|
||||
false -> "false"
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
fun test_1(b: Boolean): String = <!NO_ELSE_IN_WHEN!>when<!> (b) {
|
||||
1 == 1 -> "true"
|
||||
"" != "" -> "false"
|
||||
}
|
||||
|
||||
const val TRUE = true
|
||||
|
||||
// Already not working
|
||||
fun test_2(b: Boolean): String = <!NO_ELSE_IN_WHEN!>when<!>(b) {
|
||||
TRUE -> "true"
|
||||
false -> "false"
|
||||
}
|
||||
|
||||
const val s1 = "s1"
|
||||
const val s2 = "s2"
|
||||
|
||||
// Already not working
|
||||
fun test_3(b: Boolean): String = <!NO_ELSE_IN_WHEN!>when<!>(b) {
|
||||
true -> "true"
|
||||
s1 == s2 -> "false"
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package
|
||||
|
||||
public const val TRUE: kotlin.Boolean = true
|
||||
public const val s1: kotlin.String = "s1"
|
||||
public const val s2: kotlin.String = "s2"
|
||||
public fun test_0(/*0*/ b: kotlin.Boolean): kotlin.String
|
||||
public fun test_1(/*0*/ b: kotlin.Boolean): kotlin.String
|
||||
public fun test_2(/*0*/ b: kotlin.Boolean): kotlin.String
|
||||
public fun test_3(/*0*/ b: kotlin.Boolean): kotlin.String
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
// !LANGUAGE: -ProhibitSimplificationOfNonTrivialConstBooleanExpressions
|
||||
// ISSUE: KT-39883
|
||||
|
||||
// Should always work
|
||||
fun test_0(b: Boolean): String = when (b) {
|
||||
true -> "true"
|
||||
false -> "false"
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
fun test_1(b: Boolean): String = <!NO_ELSE_IN_WHEN!>when<!> (b) {
|
||||
1 == 1 -> "true"
|
||||
"" != "" -> "false"
|
||||
}
|
||||
|
||||
const val TRUE = true
|
||||
|
||||
// Already not working
|
||||
fun test_2(b: Boolean): String = <!NO_ELSE_IN_WHEN!>when<!>(b) {
|
||||
TRUE -> "true"
|
||||
false -> "false"
|
||||
}
|
||||
|
||||
const val s1 = "s1"
|
||||
const val s2 = "s2"
|
||||
|
||||
// Already not working
|
||||
fun test_3(b: Boolean): String = <!NO_ELSE_IN_WHEN!>when<!>(b) {
|
||||
true -> "true"
|
||||
s1 == s2 -> "false"
|
||||
}
|
||||
Vendored
+31
@@ -0,0 +1,31 @@
|
||||
// !LANGUAGE: -ProhibitSimplificationOfNonTrivialConstBooleanExpressions
|
||||
// ISSUE: KT-39883
|
||||
|
||||
// Should always work
|
||||
fun test_0(b: Boolean): String = when (b) {
|
||||
true -> "true"
|
||||
false -> "false"
|
||||
}
|
||||
|
||||
// Deprecated
|
||||
fun test_1(b: Boolean): String = when (b) {
|
||||
<!NON_TRIVIAL_BOOLEAN_CONSTANT!>1 == 1<!> -> "true"
|
||||
<!NON_TRIVIAL_BOOLEAN_CONSTANT!>"" != ""<!> -> "false"
|
||||
}
|
||||
|
||||
const val TRUE = true
|
||||
|
||||
// Already not working
|
||||
fun test_2(b: Boolean): String = <!NO_ELSE_IN_WHEN!>when<!>(b) {
|
||||
TRUE -> "true"
|
||||
false -> "false"
|
||||
}
|
||||
|
||||
const val s1 = "s1"
|
||||
const val s2 = "s2"
|
||||
|
||||
// Already not working
|
||||
fun test_3(b: Boolean): String = <!NO_ELSE_IN_WHEN!>when<!>(b) {
|
||||
true -> "true"
|
||||
s1 == s2 -> "false"
|
||||
}
|
||||
Vendored
+9
@@ -0,0 +1,9 @@
|
||||
package
|
||||
|
||||
public const val TRUE: kotlin.Boolean = true
|
||||
public const val s1: kotlin.String = "s1"
|
||||
public const val s2: kotlin.String = "s2"
|
||||
public fun test_0(/*0*/ b: kotlin.Boolean): kotlin.String
|
||||
public fun test_1(/*0*/ b: kotlin.Boolean): kotlin.String
|
||||
public fun test_2(/*0*/ b: kotlin.Boolean): kotlin.String
|
||||
public fun test_3(/*0*/ b: kotlin.Boolean): kotlin.String
|
||||
Reference in New Issue
Block a user