Skip to content

Unused import falsely reported when used in named argument #18313

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
2m opened this issue Jul 30, 2023 · 1 comment · Fixed by #20894
Closed

Unused import falsely reported when used in named argument #18313

2m opened this issue Jul 30, 2023 · 1 comment · Fixed by #20894
Assignees
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug
Milestone

Comments

@2m
Copy link

2m commented Jul 30, 2023

Compiler version

3.3.0 and 3.3.1-RC4

Minimized code

//> using scala "3.3.1-RC4"
//> using options "-Wunused:all"

import scala.deriving.Mirror

case class Test(i: Int, d: Double)
case class Decoder(d: Product => Test)

// OK, no warning returned
// val d = Decoder(summon[Mirror.Of[Test]].fromProduct)

// returns warning:
// [warn] unused import
// [warn] import scala.deriving.Mirror
val d = Decoder(d = summon[Mirror.Of[Test]].fromProduct)

Output

-- Warning: i18313.scala:4:22 -----------------------------------
4 |import scala.deriving.Mirror
  |                      ^^^^^^
  |                      unused import

Expected

No warnings

@2m 2m added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 30, 2023
@bishabosha bishabosha 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 Jul 31, 2023
@szymon-rd szymon-rd assigned szymon-rd and unassigned KacperFKorban Aug 28, 2023
@som-snytt
Copy link
Contributor

Subtly enough, uncommenting the first val makes the warning go away. Oh obviously, that's because it sees the usage.

A NamedArg is an "early tree" that requires special handling.

Confirmed broken on 3.5.1 and fixed by the linked PR.

import scala.deriving.Mirror

case class Test(i: Int, d: Double)
case class Decoder(d: Product => Test)

// OK, no warning returned
// val ok = Decoder(summon[Mirror.Of[Test]].fromProduct)
//
// returns warning:
// [warn] unused import
// [warn] import scala.deriving.Mirror
val d = Decoder(d = summon[Mirror.Of[Test]].fromProduct)

@sjrd sjrd closed this as completed in 9cb97ec Jan 28, 2025
@WojciechMazur WojciechMazur added this to the 3.7.0 milestone Mar 11, 2025
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.

6 participants