Regression for `-Wunused:import` in `business4s/decisions4s`
Opened this issue · 1 comments
WojciechMazur commented
Compiler version
3.5.0 and later
Bisect points to 975df4a
Minimized code
//> using options -Wunused:imports -Werror
object decisions4s{
trait HKD
trait DecisionTable
}
object DiagnosticsExample {
import decisions4s.HKD
case class Input[F[_]]() extends HKD
import decisions4s.*
val decisionTable: DecisionTable = ??? // warn
}
Output
[warn] ./test.scala:8:22
[warn] unused import
[warn] import decisions4s.HKD
[warn]
Expectation
Should not report warnings if wildcard import is placed after usages of explicit import statement.
som-snytt commented
I have an improvement PR and also a branch for a rewrite of the unused check, where I noticed that the scoping in "super position" is not correct:
object Constants:
final val i = 42
class `scope of super`:
import Constants.i // bad warn
class C(x: Int):
def y = x
class D extends C(i):
import Constants.* // does not resolve i in C(i)
def m = i
confirming with current scalacQ
➜ snips ~/projects/dotty/bin/scalacQ -d /tmp/sandbox -Wunused:imports import-scope.scala
-- [E198] Unused Symbol Warning: import-scope.scala:5:19 -----------------------
5 | import Constants.i // bad warn
| ^
| unused import
1 warning found
I don't think the crude scoping in the check could ever quite work; if it is a regression here in the May improvements, I assume that is because more is correctly detected.
By "crude", I mean that typer contexts are approximated.
I noticed it (on my rewrite branch, which doesn't go far) by turning on the lint in the dotty build, i.e., dogfooding.