FIR checker: support DUPLICATE_LABEL_IN_WHEN

Changes from FE1.0:
1. As discussed previously, no expression evaluation happens during this
check.
2. FE1.0 doesn't check redundant object comparisons.
This commit is contained in:
Tianyu Geng
2021-06-23 13:31:40 -07:00
committed by Mikhail Glukhikh
parent 7c6326856b
commit 4915d8dda3
12 changed files with 109 additions and 17 deletions
@@ -15,10 +15,10 @@ const val four = 4
fun first(arg: Int) = when (arg) {
1 -> 2
2 -> 3
1 -> 4
<!DUPLICATE_LABEL_IN_WHEN!>1<!> -> 4
4 -> 5
1 -> 6
2 -> 7
<!DUPLICATE_LABEL_IN_WHEN!>1<!> -> 6
<!DUPLICATE_LABEL_IN_WHEN!>2<!> -> 7
// Error should be here: see KT-11971
four -> 8
else -> 0
@@ -28,8 +28,8 @@ fun second(arg: String): Int {
when (arg) {
"ABC" -> return 0
"DEF" -> return 1
"ABC" -> return -1
"DEF" -> return -2
<!DUPLICATE_LABEL_IN_WHEN!>"ABC"<!> -> return -1
<!DUPLICATE_LABEL_IN_WHEN!>"DEF"<!> -> return -2
}
return 42
}
@@ -39,8 +39,9 @@ fun third(arg: Any?): Int {
null -> return -1
is String -> return 0
is Double -> return 1
is Double -> return 2
null -> return 3
is <!DUPLICATE_LABEL_IN_WHEN!>Double<!> -> return 2
<!DUPLICATE_LABEL_IN_WHEN!>null<!> -> return 3
!is String -> return 4
else -> return 5
}
}
@@ -50,7 +51,7 @@ enum class Color { RED, GREEN, BLUE }
fun fourth(arg: Color) = when (arg) {
Color.RED -> "RED"
Color.GREEN -> "GREEN"
Color.RED -> "BLUE"
<!DUPLICATE_LABEL_IN_WHEN!>Color.RED<!> -> "BLUE"
Color.BLUE -> "BLUE"
}
@@ -59,3 +60,11 @@ fun fifth(arg: Any?) = when (arg) {
<!ELSE_MISPLACED_IN_WHEN!>else<!> -> ""
else -> null
}
object Foo
fun sixth(arg: Any?) = when (arg) {
Foo -> ""
<!DUPLICATE_LABEL_IN_WHEN!>Foo<!> -> ""
else -> null
}
@@ -41,6 +41,7 @@ fun third(arg: Any?): Int {
is Double -> return 1
is <!DUPLICATE_LABEL_IN_WHEN!>Double<!> -> return 2
<!DUPLICATE_LABEL_IN_WHEN!>null<!> -> return 3
!is String -> return 4
else -> return 5
}
}
@@ -59,3 +60,11 @@ fun fifth(arg: Any?) = when (arg) {
<!ELSE_MISPLACED_IN_WHEN!>else<!> -> ""
<!UNREACHABLE_CODE!>else -> null<!>
}
object Foo
fun sixth(arg: Any?) = when (arg) {
Foo -> ""
Foo -> ""
else -> null
}
@@ -6,6 +6,7 @@ package test {
public fun first(/*0*/ arg: kotlin.Int): kotlin.Int
public fun fourth(/*0*/ arg: test.Color): kotlin.String
public fun second(/*0*/ arg: kotlin.String): kotlin.Int
public fun sixth(/*0*/ arg: kotlin.Any?): kotlin.String?
public fun third(/*0*/ arg: kotlin.Any?): kotlin.Int
public final enum class Color : kotlin.Enum<test.Color> {
@@ -30,4 +31,12 @@ package test {
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): test.Color
public final /*synthesized*/ fun values(): kotlin.Array<test.Color>
}
public object Foo {
private constructor Foo()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}