-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIR] Implement checker for exhaustive when's in expression position
- Loading branch information
1 parent
3f715e6
commit 8dd9d98
Showing
103 changed files
with
919 additions
and
617 deletions.
There are no files selected for viewing
139 changes: 99 additions & 40 deletions
139
...ests-gen/org/jetbrains/kotlin/fir/LazyBodyIsNotTouchedTilContractsPhaseTestGenerated.java
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
55 changes: 55 additions & 0 deletions
55
.../fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingBooleanBranch.fir.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
FILE: missingBooleanBranch.kt | ||
public final fun test_1(cond: R|kotlin/Boolean|): R|kotlin/Unit| { | ||
lval x: R|kotlin/Unit| = when (R|<local>/cond|) { | ||
==($subj$, Boolean(true)) -> { | ||
Int(1) | ||
} | ||
} | ||
|
||
lval y: R|kotlin/Unit| = when (R|<local>/cond|) { | ||
==($subj$, Boolean(false)) -> { | ||
Int(2) | ||
} | ||
} | ||
|
||
lval z: R|kotlin/Int| = when (R|<local>/cond|) { | ||
==($subj$, Boolean(true)) -> { | ||
Int(1) | ||
} | ||
==($subj$, Boolean(false)) -> { | ||
Int(2) | ||
} | ||
} | ||
|
||
} | ||
public final fun test_2(cond: R|kotlin/Boolean?|): R|kotlin/Unit| { | ||
lval x: R|kotlin/Unit| = when (R|<local>/cond|) { | ||
==($subj$, Boolean(true)) -> { | ||
Int(1) | ||
} | ||
==($subj$, Boolean(false)) -> { | ||
Int(2) | ||
} | ||
} | ||
|
||
lval x: R|kotlin/Int| = when (R|<local>/cond|) { | ||
==($subj$, Boolean(true)) -> { | ||
Int(1) | ||
} | ||
==($subj$, Boolean(false)) -> { | ||
Int(2) | ||
} | ||
==($subj$, Null(null)) -> { | ||
Int(3) | ||
} | ||
} | ||
|
||
} | ||
public final fun test_3(cond: R|kotlin/Boolean|): R|kotlin/Unit| { | ||
when (R|<local>/cond|) { | ||
==($subj$, Boolean(true)) -> { | ||
Int(1) | ||
} | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingBooleanBranch.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
fun test_1(cond: Boolean) { | ||
val x = <!NO_ELSE_IN_WHEN!>when<!> (cond) { | ||
true -> 1 | ||
} | ||
|
||
val y = <!NO_ELSE_IN_WHEN!>when<!> (cond) { | ||
false -> 2 | ||
} | ||
|
||
val z = when (cond) { | ||
true -> 1 | ||
false -> 2 | ||
} | ||
} | ||
|
||
fun test_2(cond: Boolean?) { | ||
val x = <!NO_ELSE_IN_WHEN!>when<!> (cond) { | ||
true -> 1 | ||
false -> 2 | ||
} | ||
|
||
val x = when (cond) { | ||
true -> 1 | ||
false -> 2 | ||
null -> 3 | ||
} | ||
} | ||
|
||
fun test_3(cond: Boolean) { | ||
when (cond) { | ||
true -> 1 | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingElse.fir.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
FILE: missingElse.kt | ||
public final fun test(a: R|kotlin/Any|): R|kotlin/Unit| { | ||
lval x: R|kotlin/Unit| = when (R|<local>/a|) { | ||
($subj$ is R|kotlin/Int|) -> { | ||
Int(1) | ||
} | ||
($subj$ is R|kotlin/String|) -> { | ||
Int(2) | ||
} | ||
} | ||
|
||
lval y: R|kotlin/Int| = when (R|<local>/a|) { | ||
else -> { | ||
Int(1) | ||
} | ||
} | ||
|
||
lval z: R|kotlin/Int| = when (R|<local>/a|) { | ||
($subj$ is R|kotlin/Int|) -> { | ||
Int(1) | ||
} | ||
($subj$ is R|kotlin/String|) -> { | ||
Int(2) | ||
} | ||
else -> { | ||
Int(3) | ||
} | ||
} | ||
|
||
} | ||
public final fun test_2(a: R|kotlin/Any|): R|kotlin/Unit| { | ||
when (R|<local>/a|) { | ||
($subj$ is R|kotlin/String|) -> { | ||
Int(1) | ||
} | ||
($subj$ is R|kotlin/Int|) -> { | ||
Int(2) | ||
} | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
compiler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingElse.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
fun test(a: Any) { | ||
val x = <!NO_ELSE_IN_WHEN!>when<!> (a) { | ||
is Int -> 1 | ||
is String -> 2 | ||
} | ||
|
||
val y = when (a) { | ||
else -> 1 | ||
} | ||
|
||
val z = when (a) { | ||
is Int -> 1 | ||
is String -> 2 | ||
else -> 3 | ||
} | ||
} | ||
|
||
fun test_2(a: Any) { | ||
when (a) { | ||
is String -> 1 | ||
is Int -> 2 | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
...iler/fir/analysis-tests/testData/resolve/exhaustiveness/negative/missingEnumEntry.fir.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
FILE: missingEnumEntry.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 fun test_1(enum: R|SomeEnum|): R|kotlin/Unit| { | ||
lval x: R|kotlin/Unit| = when (R|<local>/enum|) { | ||
==($subj$, Q|SomeEnum|.R|/SomeEnum.A|) -> { | ||
Int(1) | ||
} | ||
} | ||
|
||
lval y: R|kotlin/Int| = when (R|<local>/enum|) { | ||
==($subj$, Q|SomeEnum|.R|/SomeEnum.A|) -> { | ||
Int(1) | ||
} | ||
==($subj$, Q|SomeEnum|.R|/SomeEnum.B|) -> { | ||
Int(2) | ||
} | ||
} | ||
|
||
} | ||
public final fun test_2(enum: R|SomeEnum?|): R|kotlin/Unit| { | ||
lval x: R|kotlin/Unit| = when (R|<local>/enum|) { | ||
==($subj$, Q|SomeEnum|.R|/SomeEnum.A|) -> { | ||
Int(1) | ||
} | ||
==($subj$, Q|SomeEnum|.R|/SomeEnum.B|) -> { | ||
Int(2) | ||
} | ||
} | ||
|
||
lval y: R|kotlin/Int| = when (R|<local>/enum|) { | ||
==($subj$, Q|SomeEnum|.R|/SomeEnum.A|) -> { | ||
Int(1) | ||
} | ||
==($subj$, Q|SomeEnum|.R|/SomeEnum.B|) -> { | ||
Int(2) | ||
} | ||
==($subj$, Null(null)) -> { | ||
Int(3) | ||
} | ||
} | ||
|
||
} | ||
public final fun test_3(enum: R|SomeEnum|): R|kotlin/Unit| { | ||
when (R|<local>/enum|) { | ||
==($subj$, Q|SomeEnum|.R|/SomeEnum.A|) -> { | ||
Int(1) | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.