Skip to content

3.3.0-RC4 -Wunused:imports false positive for imports that are only used in imports #17314

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Lasering opened this issue Apr 19, 2023 · 1 comment · Fixed by #17323
Closed
Assignees
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@Lasering
Copy link

Lasering commented Apr 19, 2023

Compiler version

3.3.0-RC4

Minimized code

Define some givens in a base package:

package com.base

import java.net.URI
import io.circe.Codec
import io.circe.derivation.Configuration

given Configuration = ???
given Codec[URI] = ???

Import those givens explicitly by type in another package:

package com.base.models

import java.net.URI
import io.circe.Codec
import io.circe.derivation.{Configuration, ConfiguredCodec}
import com.base.{given Configuration, given Codec[URI]}

case class Operator(url: Option[URI]) derives ConfiguredCodec

Output

The compiler gives the following warnings:

import io.circe.Codec
                ^^^^^
                unused import
import io.circe.derivation.{Configuration, ConfiguredCodec}
                            ^^^^^^^^^^^^^
                            unused import
import com.base.{given Configuration, given Codec[URI]}
                                      ^^^^^^^^^^^^^^^^
                                      unused import

Expectation

No warning should be emitted. Please note:

  • Configuration and Codec were only imported to be used in import com.base.{given Configuration, given Codec[URI]} the rest of the file does not use those types.
  • the method ConfiguredCodec.derived expects a Configuration instance to be in the implicit scope.
  • Codec[URI] will be used while deriving the ConfiguredCodec.
@Lasering Lasering added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 19, 2023
@Lasering Lasering changed the title -Wunused:imports false positive for imports that are only used in imports 3.3.0-RC4 -Wunused:imports false positive for imports that are only used in imports Apr 19, 2023
@jchyb jchyb added area:linting Linting warnings enabled with -W or -Xlint and removed stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 20, 2023
@jchyb
Copy link
Contributor

jchyb commented Apr 20, 2023

One file, no dependency minimization:

package circelike {
  import java.net.URI
  import scala.compiletime.{erasedValue, summonInline}
  import scala.deriving.Mirror

  type Codec[T]
  type Configuration
  trait ConfiguredCodec[T]
  object ConfiguredCodec:

    inline final def derived[A](using conf: Configuration)(using
      inline mirror: Mirror.Of[A]
    ): ConfiguredCodec[A] =
      new ConfiguredCodec[A]:
        val codec = summonInline[Codec[URI]] // simplification
}

package foo {
  import java.net.URI
  import circelike.{Codec, Configuration}

  given Configuration = ???
  given Codec[URI] = ???
}

package bar {
  import java.net.URI
  import circelike.Codec
  import circelike.{Configuration, ConfiguredCodec}
  import foo.{given Configuration, given Codec[URI]}

  case class Operator(url: URI) derives ConfiguredCodec
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants