Skip to content

import shadows enclosing packaging #11296

Closed
@som-snytt

Description

@som-snytt

Compiler version

Scala compiler version 3.0.0-M3 -- Copyright 2002-2020, LAMP/EPFL

Minimized code

// test.scala
package p {
  class C
}

package q {
  package p {
    class K {
      import _root_.p
      def f() = new p.C
    }
  }
}

Output

Hey, it compiles!

Expectation

An import cannot shadow an enclosing definition.

s/package p/object p results in expected ambiguous reference.

Arguably a package is not a definition, the symbol is introduced by a packaging.

Here, q.p is made available via packagings in the current compilation unit; for definitions, that binding is higher precedence than an import.

Possibly, this behavior is expected or understood, and the spec should say explicitly that bindings of names of packagings are always of least precedence.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions