Hi all,
On Scala 3.3.7 with -Wunused:imports, I’m getting a false-positive “unused import” on a given wildcard import that the code needs. Removing it breaks the compile.
The library declares the given inside a library-private trait that’s mixed into a public object. I can’t name the specific given for a targeted import (the declaring trait is private), so I need the whole given. An operator defined elsewhere in the library resolves implicitly to that given. The unused-imports checker doesn’t trace implicit resolution through the mixin chain and flags the import as unused.
I’d like to suppress this one warning with @nowarn. Three forms I tried, none worked:
- @nowarn(“msg=unused import”) import api.given → parse error: Expected start of definition
- @nowarn on the enclosing case class → warning still fires (imports are file-level)
- Move import api.given inside the class body, @nowarn on it → same parse error
Is there a supported syntax to annotate an import with @nowarn in 3.3.x? Short of a file-scoped -Wconf:src=…&cat=unused-imports:s in the build, is there an idiomatic way to quiet this?
Thanks,
David
import scala.annotation.nowarn
import calico.html.io.{button, cls, div, onClick, styleAttr, given}
import cats.effect.{IO, Resource}
import fs2.concurrent.SignallingRef
import fs2.dom.HtmlElement
class Widget:
def render: Resource[IO, HtmlElement[IO]] =
for
show <- SignallingRef[IO].of(false).toResource
popup <- div(
styleAttr <-- show.map(s => if s then "display: block" else "display: none"),
button(
onClick --> (_.foreach(_ => show.set(false))),
"Done"
)
)
widget <- div(
cls := "ctrl",
popup
)
yield widget
// Attempts that do NOT suppress the warning on Scala 3.3.7:
//
// @nowarn("msg=unused import") import calico.html.io.given
// → parse error: "Expected start of definition"
//
// @nowarn("msg=unused import")
// class Widget: ... // ignored — imports are file-level
//
// class Widget:
// @nowarn("msg=unused import")
// import calico.html.io.given // parse error