benleggiero
02/19/2018, 4:21 AMimport Foo.*
import Bar.*
enum class Foo {
a,
b,
c
}
enum class Bar {
a,
b,
c
}
fun translate(x: Foo): Bar = when (x) {
b -> a
a -> b
c -> c
}
val fooBar = translate(a)
Error:(21, 30) Kotlin: 'when' expression must be exhaustive, add necessary 'a', 'b', 'c' branches or 'else' branch instead
Error:(22, 5) Kotlin: Unresolved reference: b
Error:(22, 10) Kotlin: Unresolved reference: a
Error:(23, 5) Kotlin: Unresolved reference: a
Error:(23, 10) Kotlin: Unresolved reference: b
Error:(24, 5) Kotlin: Unresolved reference: c
Error:(24, 10) Kotlin: Unresolved reference: c
Error:(29, 24) Kotlin: Unresolved reference: a
And the only way to resolve these is to say Foo.a
or Bar.c
everwhere a member of either is needed. With proper IME support, .a
and .c
would do the job every time without ambiguity.groostav
02/24/2018, 9:07 PMbenleggiero
02/25/2018, 7:15 PM