wasyl
08/07/2024, 9:20 AMenum class Foo {
Bar,
Baz,
}
fun foo(foo: Foo) = when (foo) {
Foo.Bar -> 2
Foo.Baz -> 3
}
fun main() {
println(foo(Foo.Bar))
}
Is there any inspection I can run to find out that Foo.Baz
can be removed? I want to find actually unused code, and Foo.Baz
is effectively unreachable if nothing ever uses Foo.Bar
as value parameter (?) or assignment valueCLOVIS
08/07/2024, 10:21 AMFoo.entries()
. If this is a library, some external code could be using it too.wasyl
08/07/2024, 10:26 AMIf this is a library, some external code could be using it too.that's fair, but I still want to run it if I know all my modules are self-contained if I'm developing an application, or if the identifiers are not public
Code could be usingThat's right 😕 Same for sealed classes and reflection I guess, but I'd still want to find declarations without explicit usage. Technically it might not be correct, but it'd still be usefulFoo.entries()
CLOVIS
08/07/2024, 10:27 AMwasyl
08/07/2024, 10:28 AMchristophsturm
08/07/2024, 10:30 AMprivate
you will get a notification “value of parameter foo is alway Foo.Bar”christophsturm
08/07/2024, 10:31 AMwasyl
08/07/2024, 10:36 AMprivate enum class Foo {
Bar,
Baz,
Baa,
}
private fun foo(foo: Foo) = when (foo) {
Foo.Bar -> 2
Foo.Baz -> 3
Foo.Baa -> 4
}
private fun main() {
println(foo(Foo.Bar))
println(foo(Foo.Baa))
}
christophsturm
08/07/2024, 10:37 AMwasyl
08/07/2024, 10:38 AMenum class
or a sealed interfaces
with ~20-40 entries, and those entries are all mapped to something else in one function.
Then application code passes these enum/interface classes somewhere, but at some point some of the entries might stop being used. They'll still be mapped so technically used as far as IDE is concerned, but I want to find candidates to removewasyl
08/07/2024, 10:38 AMchristophsturm
08/07/2024, 10:38 AMchristophsturm
08/07/2024, 10:39 AMwasyl
08/07/2024, 10:39 AMwhen
) but never written (passed)christophsturm
08/07/2024, 10:40 AMwasyl
08/07/2024, 10:43 AMwasyl
08/07/2024, 11:20 AM