[FIR] Add regression tests for number of issues fixed in K2
List of issues: KT-4113, KT-6822, KT-7389, KT-17817, KT-20223 KT-21463, KT-24503, KT-24737, KT-24779, KT-24901 KT-27261, KT-28668, KT-30497, KT-30756, KT-36958 KT-37365, KT-37490, KT-38288, KT-41038, KT-41721 KT-42136, KT-42169, KT-42449, KT-42715, KT-43553 KT-43603, KT-43846, KT-43936, KT-46288, KT-46301 KT-47373, KT-47484, KT-47490, KT-47495, KT-47750 KT-47815, KT-47870, KT-48975, KT-49024, KT-49045 KT-50134, KT-50160, KT-50550, KT-51045, KT-51143 KT-51796, KT-52262, KT-52424, KT-52860, KT-52934 KT-53086, KT-53494, KT-53671, KT-53752, KT-53819 KT-54478, KT-54518, KT-54931, KT-54990, KT-55138 KT-55379, KT-55555, KT-56243
This commit is contained in:
committed by
Space Team
parent
8ae5213155
commit
aef9b129d2
Vendored
+29
@@ -0,0 +1,29 @@
|
||||
FILE: annotatedBranch.kt
|
||||
public final enum class SomeEnum : R|kotlin/Enum<SomeEnum>| {
|
||||
private constructor(): R|SomeEnum| {
|
||||
super<R|kotlin/Enum<SomeEnum>|>()
|
||||
}
|
||||
|
||||
public final static enum entry A: R|SomeEnum|
|
||||
public final static enum entry B: R|SomeEnum|
|
||||
public final static fun values(): R|kotlin/Array<SomeEnum>| {
|
||||
}
|
||||
|
||||
public final static fun valueOf(value: R|kotlin/String|): R|SomeEnum| {
|
||||
}
|
||||
|
||||
public final static val entries: R|kotlin/enums/EnumEntries<SomeEnum>|
|
||||
public get(): R|kotlin/enums/EnumEntries<SomeEnum>|
|
||||
|
||||
}
|
||||
public final fun test(x: R|SomeEnum|): R|kotlin/Unit| {
|
||||
when (R|<local>/x|) {
|
||||
==($subj$, Q|SomeEnum|.R|/SomeEnum.A|) -> {
|
||||
Int(1)
|
||||
}
|
||||
==($subj$, @R|kotlin/Suppress|(names = vararg(String(deprecation))) Q|SomeEnum|.R|/SomeEnum.B|) -> {
|
||||
Int(2)
|
||||
}
|
||||
}
|
||||
.R|kotlin/Int.inc|()
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
// ISSUE: KT-50550
|
||||
|
||||
enum class SomeEnum { A, B}
|
||||
|
||||
fun test(x: SomeEnum) {
|
||||
when (x) {
|
||||
SomeEnum.A -> 1
|
||||
@Suppress("deprecation")
|
||||
SomeEnum.B -> 2
|
||||
}.inc()
|
||||
}
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
FILE: exhaustiveness_smartcastedBoolean.kt
|
||||
public final fun test_1(b: R|kotlin/Any|): R|kotlin/Unit| {
|
||||
R|kotlin/require|((R|<local>/b| is R|kotlin/Boolean|))
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/b|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
}
|
||||
|
||||
lval y: R|kotlin/Int| = when (R|<local>/b|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
==($subj$, Boolean(false)) -> {
|
||||
Int(2)
|
||||
}
|
||||
}
|
||||
|
||||
lval z: R|kotlin/Int| = when (R|<local>/b|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
else -> {
|
||||
Int(2)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public final fun test_2(b: R|kotlin/Any?|): R|kotlin/Unit| {
|
||||
R|kotlin/require|((R|<local>/b| is R|kotlin/Boolean?|))
|
||||
lval x: R|kotlin/Unit| = when (R|<local>/b|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
==($subj$, Boolean(false)) -> {
|
||||
Int(2)
|
||||
}
|
||||
}
|
||||
|
||||
lval y: R|kotlin/Int| = when (R|<local>/b|) {
|
||||
==($subj$, Boolean(true)) -> {
|
||||
Int(1)
|
||||
}
|
||||
==($subj$, Boolean(false)) -> {
|
||||
Int(2)
|
||||
}
|
||||
==($subj$, Null(null)) -> {
|
||||
Int(3)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-55379
|
||||
|
||||
fun test_1(b: Any) {
|
||||
require(b is Boolean)
|
||||
val x = <!NO_ELSE_IN_WHEN!>when<!> (b) {
|
||||
true -> 1
|
||||
}
|
||||
val y = when (b) {
|
||||
true -> 1
|
||||
false -> 2
|
||||
}
|
||||
val z = when (b) {
|
||||
true -> 1
|
||||
else -> 2
|
||||
}
|
||||
}
|
||||
|
||||
fun test_2(b: Any?) {
|
||||
require(b is Boolean?)
|
||||
val x = <!NO_ELSE_IN_WHEN!>when<!> (b) {
|
||||
true -> 1
|
||||
false -> 2
|
||||
}
|
||||
val y = when (b) {
|
||||
true -> 1
|
||||
false -> 2
|
||||
null -> 3
|
||||
}
|
||||
}
|
||||
+50
@@ -0,0 +1,50 @@
|
||||
FILE: sameBranchMultipleConditions.kt
|
||||
public sealed interface A : R|kotlin/Any| {
|
||||
}
|
||||
public sealed interface B : R|kotlin/Any| {
|
||||
}
|
||||
public final data class X : R|A|, R|B| {
|
||||
public constructor(something: R|kotlin/String|): R|X| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val something: R|kotlin/String| = R|<local>/something|
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
public final operator fun component1(): R|kotlin/String|
|
||||
|
||||
public final fun copy(something: R|kotlin/String| = this@R|/X|.R|/X.something|): R|X|
|
||||
|
||||
}
|
||||
public final data class Y : R|A|, R|B| {
|
||||
public constructor(something: R|kotlin/String|): R|Y| {
|
||||
super<R|kotlin/Any|>()
|
||||
}
|
||||
|
||||
public final val something: R|kotlin/String| = R|<local>/something|
|
||||
public get(): R|kotlin/String|
|
||||
|
||||
public final operator fun component1(): R|kotlin/String|
|
||||
|
||||
public final fun copy(something: R|kotlin/String| = this@R|/Y|.R|/Y.something|): R|Y|
|
||||
|
||||
}
|
||||
public final fun ok(a: R|A|): R|B| {
|
||||
^ok when (R|<local>/a|) {
|
||||
($subj$ is R|X|) -> {
|
||||
R|<local>/a|
|
||||
}
|
||||
($subj$ is R|Y|) -> {
|
||||
R|<local>/a|
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public final fun problem(a: R|A|): R|B| {
|
||||
^problem when (R|<local>/a|) {
|
||||
($subj$ is R|X|) || ($subj$ is R|Y|) -> {
|
||||
R|<local>/a|
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
compiler/fir/analysis-tests/testData/resolve/exhaustiveness/positive/sameBranchMultipleConditions.kt
Vendored
+20
@@ -0,0 +1,20 @@
|
||||
// ISSUE: KT-46301
|
||||
|
||||
sealed interface A
|
||||
sealed interface B
|
||||
|
||||
data class X(val something: String): A, B
|
||||
data class Y(val something: String): A, B
|
||||
|
||||
fun ok(a: A): B {
|
||||
return when (a) {
|
||||
is X -> a
|
||||
is Y -> a
|
||||
}
|
||||
}
|
||||
|
||||
fun problem(a: A): B {
|
||||
return when (a) {
|
||||
is X, is Y -> a
|
||||
}
|
||||
}
|
||||
+78
@@ -0,0 +1,78 @@
|
||||
FILE: smartcastToExhaustiveInterface.kt
|
||||
public sealed interface I1 : R|kotlin/Any| {
|
||||
public abstract interface B : R|I1| {
|
||||
}
|
||||
|
||||
public abstract interface C : R|I1| {
|
||||
}
|
||||
|
||||
}
|
||||
public sealed interface I2 : R|kotlin/Any| {
|
||||
public abstract interface B : R|I2| {
|
||||
}
|
||||
|
||||
public abstract interface C : R|I2| {
|
||||
}
|
||||
|
||||
}
|
||||
public final fun test_1(x: R|I1|): R|kotlin/Unit| {
|
||||
lval a: R|kotlin/Int| = when (R|<local>/x|) {
|
||||
($subj$ is R|I1.B|) -> {
|
||||
Int(1)
|
||||
}
|
||||
($subj$ is R|I1.C|) -> {
|
||||
Int(1)
|
||||
}
|
||||
}
|
||||
|
||||
R|kotlin/require|((R|<local>/x| is R|I2|))
|
||||
lval b: R|kotlin/Int| = when (R|<local>/x|) {
|
||||
($subj$ is R|I1.B|) -> {
|
||||
Int(1)
|
||||
}
|
||||
($subj$ is R|I1.C|) -> {
|
||||
Int(1)
|
||||
}
|
||||
}
|
||||
|
||||
lval c: R|kotlin/Int| = when (R|<local>/x|) {
|
||||
($subj$ is R|I2.B|) -> {
|
||||
Int(1)
|
||||
}
|
||||
($subj$ is R|I2.C|) -> {
|
||||
Int(1)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public final fun test_2(x: R|kotlin/Any|): R|kotlin/Unit| {
|
||||
R|kotlin/require|((R|<local>/x| is R|I1|))
|
||||
lval a: R|kotlin/Int| = when (R|<local>/x|) {
|
||||
($subj$ is R|I1.B|) -> {
|
||||
Int(1)
|
||||
}
|
||||
($subj$ is R|I1.C|) -> {
|
||||
Int(1)
|
||||
}
|
||||
}
|
||||
|
||||
R|kotlin/require|((R|<local>/x| is R|I2|))
|
||||
lval b: R|kotlin/Int| = when (R|<local>/x|) {
|
||||
($subj$ is R|I1.B|) -> {
|
||||
Int(1)
|
||||
}
|
||||
($subj$ is R|I1.C|) -> {
|
||||
Int(1)
|
||||
}
|
||||
}
|
||||
|
||||
lval c: R|kotlin/Int| = when (R|<local>/x|) {
|
||||
($subj$ is R|I2.B|) -> {
|
||||
Int(1)
|
||||
}
|
||||
($subj$ is R|I2.C|) -> {
|
||||
Int(1)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+46
@@ -0,0 +1,46 @@
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-47750
|
||||
|
||||
sealed interface I1 {
|
||||
interface B : I1
|
||||
interface C : I1
|
||||
}
|
||||
|
||||
sealed interface I2 {
|
||||
interface B : I2
|
||||
interface C : I2
|
||||
}
|
||||
|
||||
fun test_1(x: I1) {
|
||||
val a = when (x) {
|
||||
is I1.B -> 1
|
||||
is I1.C -> 1
|
||||
}
|
||||
require(x is I2)
|
||||
val b = when (x) {
|
||||
is I1.B -> 1
|
||||
is I1.C -> 1
|
||||
}
|
||||
|
||||
val c = when (x) {
|
||||
is I2.B -> 1
|
||||
is I2.C -> 1
|
||||
}
|
||||
}
|
||||
|
||||
fun test_2(x: Any) {
|
||||
require(x is I1)
|
||||
val a = when (x) {
|
||||
is I1.B -> 1
|
||||
is I1.C -> 1
|
||||
}
|
||||
require(x is I2)
|
||||
val b = when (x) {
|
||||
is I1.B -> 1
|
||||
is I1.C -> 1
|
||||
}
|
||||
val c = when (x) {
|
||||
is I2.B -> 1
|
||||
is I2.C -> 1
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user