Skip to content

First applicable import is marked used when ambiguity is resolved #13073

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

Open
som-snytt opened this issue Jan 2, 2025 · 0 comments
Open

First applicable import is marked used when ambiguity is resolved #13073

som-snytt opened this issue Jan 2, 2025 · 0 comments

Comments

@som-snytt
Copy link

//> using scala 2.13.15
//> using options -Wunused:imports -Xsource:3

import Dog.Owner

class Dog(owner: Owner) {
  import Dog.*

  val getOwner: Owner = owner
}

object Dog {
  class Owner
}

Problem

Unlike future dotty, there is no warning for the inner import, most likely because the compiler picks it after reconciling with the outer import. It would be equally valid to pick the higher-precedence binding.

Conversely, it's desirable perhaps to "use" the import of smallest scope and report the other unused if possible. That is, this is where separate analysis shines: the compiler behavior per se doesn't matter for "minimizing" imports.

If the outer import were also wildcard, and so, equal precedence, it's also preferable to warn about the inner import. For simplicity, pick the highest precedence, outermost import as "canonical form".

The example is due to scala/scala3#21917

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant