Skip to content

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

Open
@som-snytt

Description

@som-snytt
//> 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions