CFG exhaustive when else instruction for KT-8700
This commit is contained in:
committed by
Mikhail Glukhikh
parent
697228eae0
commit
b805ce06c2
@@ -0,0 +1,14 @@
|
||||
enum class Color { RED, GREEN, BLUE }
|
||||
|
||||
fun foo(arr: Array<Color>): Color {
|
||||
loop@ for (color in arr) {
|
||||
when (color) {
|
||||
Color.RED -> return color
|
||||
Color.GREEN -> break@loop
|
||||
Color.BLUE -> if (arr.size == 1) return color else continue@loop
|
||||
}
|
||||
// Unreachable
|
||||
<!UNREACHABLE_CODE!>return Color.BLUE<!>
|
||||
}
|
||||
return Color.GREEN
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ arr: kotlin.Array<Color>): Color
|
||||
|
||||
public final enum class Color : kotlin.Enum<Color> {
|
||||
enum entry RED
|
||||
|
||||
enum entry GREEN
|
||||
|
||||
enum entry BLUE
|
||||
|
||||
private constructor Color()
|
||||
public final override /*1*/ /*fake_override*/ val name: kotlin.String
|
||||
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
|
||||
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
|
||||
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: Color): kotlin.Int
|
||||
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use 'values()' function instead", replaceWith = kotlin.ReplaceWith(expression = "this.values()", imports = {})) public final /*synthesized*/ val values: kotlin.Array<Color>
|
||||
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): Color
|
||||
public final /*synthesized*/ fun values(): kotlin.Array<Color>
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fun foo(b: Boolean): Int {
|
||||
val x: Int
|
||||
val y: Int
|
||||
when (b) {
|
||||
true -> y = 1
|
||||
false -> y = 0
|
||||
}
|
||||
// x is initialized here
|
||||
x = 3
|
||||
return x + y
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ b: kotlin.Boolean): kotlin.Int
|
||||
@@ -0,0 +1,14 @@
|
||||
enum class Direction {
|
||||
NORTH, SOUTH, WEST, EAST
|
||||
}
|
||||
|
||||
fun foo(dir: Direction): Int {
|
||||
when (dir) {
|
||||
Direction.NORTH -> return 1
|
||||
Direction.SOUTH -> throw AssertionError("!!!")
|
||||
Direction.WEST -> return 3
|
||||
Direction.EAST -> return 4
|
||||
}
|
||||
// Error: Unreachable code. Return is not required.
|
||||
<!UNREACHABLE_CODE!>if (dir == Direction.SOUTH) return 2<!>
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package
|
||||
|
||||
public fun foo(/*0*/ dir: Direction): kotlin.Int
|
||||
|
||||
public final enum class Direction : kotlin.Enum<Direction> {
|
||||
enum entry NORTH
|
||||
|
||||
enum entry SOUTH
|
||||
|
||||
enum entry WEST
|
||||
|
||||
enum entry EAST
|
||||
|
||||
private constructor Direction()
|
||||
public final override /*1*/ /*fake_override*/ val name: kotlin.String
|
||||
public final override /*1*/ /*fake_override*/ val ordinal: kotlin.Int
|
||||
protected final override /*1*/ /*fake_override*/ fun clone(): kotlin.Any
|
||||
public final override /*1*/ /*fake_override*/ fun compareTo(/*0*/ other: Direction): kotlin.Int
|
||||
public final override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public final override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
|
||||
// Static members
|
||||
@kotlin.Deprecated(level = DeprecationLevel.ERROR, message = "Use 'values()' function instead", replaceWith = kotlin.ReplaceWith(expression = "this.values()", imports = {})) public final /*synthesized*/ val values: kotlin.Array<Direction>
|
||||
public final /*synthesized*/ fun valueOf(/*0*/ value: kotlin.String): Direction
|
||||
public final /*synthesized*/ fun values(): kotlin.Array<Direction>
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
fun foo(a: Boolean, b: Boolean): Int {
|
||||
val x: Int
|
||||
if (a) {
|
||||
x = 1
|
||||
}
|
||||
when (b) {
|
||||
true -> <!VAL_REASSIGNMENT!>x<!> = 2
|
||||
false -> x = 3
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
fun bar(a: Boolean, b: Boolean): Int {
|
||||
val x: Int
|
||||
if (a) {
|
||||
x = 1
|
||||
}
|
||||
when (b) {
|
||||
false -> <!VAL_REASSIGNMENT!>x<!> = 3
|
||||
}
|
||||
return <!UNINITIALIZED_VARIABLE!>x<!>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun bar(/*0*/ a: kotlin.Boolean, /*1*/ b: kotlin.Boolean): kotlin.Int
|
||||
public fun foo(/*0*/ a: kotlin.Boolean, /*1*/ b: kotlin.Boolean): kotlin.Int
|
||||
@@ -0,0 +1,22 @@
|
||||
fun foo(a: Boolean, b: Boolean): Int {
|
||||
var x: Int
|
||||
if (a) {
|
||||
x = 1
|
||||
}
|
||||
when (b) {
|
||||
true -> x = 2
|
||||
false -> x = 3
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
fun bar(a: Boolean, b: Boolean): Int {
|
||||
var x: Int
|
||||
if (a) {
|
||||
x = 1
|
||||
}
|
||||
when (b) {
|
||||
false -> x = 3
|
||||
}
|
||||
return <!UNINITIALIZED_VARIABLE!>x<!>
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package
|
||||
|
||||
public fun bar(/*0*/ a: kotlin.Boolean, /*1*/ b: kotlin.Boolean): kotlin.Int
|
||||
public fun foo(/*0*/ a: kotlin.Boolean, /*1*/ b: kotlin.Boolean): kotlin.Int
|
||||
Reference in New Issue
Block a user