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

3.3.0-RC5 -Wunused:imports false positive for imports that "shadow" other imports #17371

Closed
Lasering opened this issue Apr 29, 2023 · 3 comments · Fixed by #20894
Closed

3.3.0-RC5 -Wunused:imports false positive for imports that "shadow" other imports #17371

Lasering opened this issue Apr 29, 2023 · 3 comments · Fixed by #20894
Labels
area:linting Linting warnings enabled with -W or -Xlint itype:bug

Comments

@Lasering
Copy link

Lasering commented Apr 29, 2023

Compiler version

3.3.0-RC5 with -Wunused:imports flag on.

Minimized code

trait Circular[T] extends Ordering[T]
trait Turns[C: Circular, T] extends Ordering[T]:
  extension (turns: T)
    def extract: C

def foo[K, T](start: T, end: T)(using circular: Circular[K], turns: Turns[K, T]): Boolean =
  import turns.given
  if start > end then throw new IllegalArgumentException("start must be <= end")
  
  import circular.given
  start.extract < end.extract

Output

 10 |    import turns.given
    |                 ^^^^^
    |                 unused import

Expectation

No warning should be emitted.

@Lasering Lasering added itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Apr 29, 2023
@KacperFKorban KacperFKorban 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 29, 2023
@KacperFKorban
Copy link
Member

Minimized a bit to use less language features:

//> using scala "3.3.0-RC5"
//> using options "-Wunused:all"

class A
class B

def Test() =
  val ordA: Ordering[A] = ???
  val ordB: Ordering[B] = ???
  val a: A = ???
  val b: B = ???

  import ordA.given
  val _ = a > a
  
  import ordB.given // warn: Unused
  val _ = b < b

Output:

-- Warning: i17371.scala:16:14 ----------------------------------
16 |  import ordB.given // warn: Unused
   |              ^^^^^
   |              unused import

@odersky
Copy link
Contributor

odersky commented Aug 23, 2023

I have no idea why this one behaves as it does. If we adopt the strategy "an import is used if code refers to some of its imported symbols" this should compile without warning, since mkOrderingOps is selected from ordB.

@som-snytt
Copy link
Contributor

This is the first issue addressed on the linked PR: mkOrderingOps is selected from both imports, albeit with different prefixes.

You might expect the code to use the nearest enclosing import context in that case, but contexts are broken in this context.

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