Skip to content

Scala 2 less generous than 3 on import ambiguity #13066

Open
@som-snytt

Description

Reproduction steps

Scala version: 2.13.15

package testsamepackageimport {
  package p {
    class C
  }

  package p {
    package q {
      import p._ // warn
      class U {
        def f = new C
      }
    }
  }
}

errors

pkg-import.scala:11: error: reference to C is ambiguous;
it is both defined in package p and imported subsequently by
import p._
        def f = new C
                    ^
pkg-import.scala:9: warning: Unused import
      import p._ // warn
               ^
1 warning
1 error

but does not error at the same nesting level

package testsamepackageimport {
  package p {
    class C
  }

  package p {
    import p._ // warn
    package q {
      class U {
        def f = new C
      }
    }
  }
}

Problem

It should only error if the competing import and definition resolve to different symbols.

The import is unused but not erroneous.

Scala 3 does not error.

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