-
-
Save Dobiasd/a7292aaf8f818e3303a2cfc55c69c6ab to your computer and use it in GitHub Desktop.
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
package exhaustiveWhen | |
fun printSomething() = println(42) | |
fun returnSomething(): Int = 42 | |
enum class Foo { A, B } | |
open class Base | |
class Derived1 : Base() | |
class Derived2 : Base() | |
// enum or class | |
// normal or let | |
// statement or assignment | |
// unit or value | |
// EC NL SA UV ORF | |
// E N S U R | |
// C N S U O | |
// E N S V R | |
// C N S V O | |
// E L S U R | |
// C L S U O | |
// E L S V F | |
// C L S V F | |
// E N A U F | |
// C N A U F | |
// E N A V F | |
// C N A V F | |
// E L A U R | |
// C L A U O | |
// E L A V F | |
// C L A V F | |
fun ensu(x: Foo) { | |
when (x) { // Recommendation only | |
Foo.A -> { | |
printSomething() | |
} | |
} | |
} | |
fun cnsu(x: Base) { | |
when (x) { // OK | |
is Derived1 -> { | |
printSomething() | |
} | |
} | |
} | |
fun ensv(x: Foo) { | |
when (x) { // Recommendation only | |
Foo.A -> { | |
returnSomething() | |
} | |
} | |
} | |
fun cnsv(x: Base) { | |
when (x) { // OK | |
is Derived1 -> { | |
returnSomething() | |
} | |
} | |
} | |
fun elsu(x: Foo) { | |
x.let { | |
when (it) { // Recommendation only | |
Foo.A -> { | |
printSomething() | |
} | |
} | |
} | |
} | |
fun clsu(x: Base) { | |
x.let { | |
when (it) { // OK | |
is Derived1 -> { | |
printSomething() | |
} | |
} | |
} | |
} | |
fun elsv(x: Foo) { | |
x.let { | |
when (it) { // Failure | |
Foo.A -> { | |
returnSomething() | |
} | |
} | |
} | |
} | |
fun clsv(x: Base) { | |
x.let { | |
when (it) { // Failure | |
is Derived1 -> { | |
returnSomething() | |
} | |
} | |
} | |
} | |
fun enau(x: Foo) { | |
val y = when (x) { // Failure | |
Foo.A -> { | |
printSomething() | |
} | |
} | |
} | |
fun cnau(x: Base) { | |
val y = when (x) { // Failure | |
is Derived1 -> { | |
printSomething() | |
} | |
} | |
} | |
fun enav(x: Foo) { | |
val y = when (x) { // Failure | |
Foo.A -> { | |
returnSomething() | |
} | |
} | |
} | |
fun cnav(x: Base) { | |
val y = when (x) { // Failure | |
is Derived1 -> { | |
returnSomething() | |
} | |
} | |
} | |
fun elau(x: Foo) { | |
val y = x.let { | |
when (it) { // Recommendation only | |
Foo.A -> { | |
printSomething() | |
} | |
} | |
} | |
} | |
fun clau(x: Base) { | |
val y = x.let { | |
when (it) { // OK | |
is Derived1 -> { | |
printSomething() | |
} | |
} | |
} | |
} | |
fun elav(x: Foo) { | |
val y = x.let { | |
when (it) { // Failure | |
Foo.A -> { | |
returnSomething() | |
} | |
} | |
} | |
} | |
fun clav(x: Base) { | |
val y = x.let { | |
when (it) { // Failure | |
is Derived1 -> { | |
returnSomething() | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment