Closed som-snytt closed 6 months ago
What about
class `t12992 enclosing def is unused` {
private val n = 42
@annotation.unused def f() = n + 2 // unused code uses n
}
Is n
unused? The PR doesn't look inside f
.
I like that behavior but it's necessary to consider side effects.
In this example, max is untested but you must inspect the rhs for update of the var.
var evaluatedCountOfMaxBy = 0
val max = list.maxBy(x => {
evaluatedCountOfMaxBy += 1
x * 10
})
not sure why I wrote this trick, but it is undone.
type ignore = annotation.unused
@ignore def ignore: ignore = ??? // ignore that ignore looks unused
Avoid warning if method is marked unused.
https://github.com/scala/scala/blob/v2.13.14/src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala#L99
Avoid warning if parameter type is singleton.
https://github.com/scala/scala/blob/v2.13.14/src/compiler/scala/tools/nsc/ast/TreeDSL.scala#L132
Problem
Probably all unused warnings should be silenced by unused enclosing definition, much like deprecation.