Skip to content
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

False warning about unused import for local/relative import with Scala 3.3 #18366

Closed
cchantep opened this issue Aug 8, 2023 · 3 comments · Fixed by #18468 or #18617 · May be fixed by #18400
Closed

False warning about unused import for local/relative import with Scala 3.3 #18366

cchantep opened this issue Aug 8, 2023 · 3 comments · Fixed by #18468 or #18617 · May be fixed by #18400
Assignees
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@cchantep
Copy link
Contributor

cchantep commented Aug 8, 2023

Compiler version

3.3.0 & 3.3.1-RC4

Minimized code

  @SuppressWarnings(Array("UnusedMethodParameter"))
  private[api] def serializeWith[P <: SerializationPack](
      pack: P,
      collation: Collation
    )(builder: SerializationPack.Builder[pack.type]
    ): pack.Document = {

    import builder.{ elementProducer => element, int, string, boolean }

    val elements = Seq.newBuilder[pack.ElementProducer]

    elements += element("locale", string(collation.locale))
    ??? // ...
}

See: https://github.com/ReactiveMongo/ReactiveMongo/blob/master/driver/src/main/scala/api/Collation.scala#L166

Output

[error] 166 |    import builder.{ elementProducer => element, int, string, boolean }
[error]     |                     ^^^^^^^^^^^^^^^^^^^^^^^^^^
[error]     |                     unused import

Expectation

No warning

@cchantep cchantep added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Aug 8, 2023
@dwijnand dwijnand 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 Aug 8, 2023
@Kordyjan Kordyjan added this to the 3.3.2 milestone Aug 9, 2023
@szymon-rd szymon-rd added the stat:needs minimization Needs a self contained minimization label Aug 9, 2023
@szymon-rd
Copy link
Contributor

Minimized repro:

trait Builder {
  def foo(): Unit
}

def repro =
  val builder: Builder = ???
  import builder.{foo => bar}
  bar()

@odersky
Copy link
Contributor

odersky commented Aug 23, 2023

I think this one can also be addressed by counting an import as used if some code refers to its imported symbols (under either name). Here, we would see a reference to foo in the code, and foo is the original name of an imported symbol, so we count the import as used.

It converts a false negative into a false positive (i.e. now we might fail to warn), but the false positive is a rare corner case, so is acceptable.

@szymon-rd
Copy link
Contributor

Reopening as commits fixing it were reverted (causing nondeterministic failures in tests)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment