Skip to content

Imported packaging shadows packaging in scope #9889

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

Closed
som-snytt opened this issue Sep 26, 2020 · 1 comment
Closed

Imported packaging shadows packaging in scope #9889

som-snytt opened this issue Sep 26, 2020 · 1 comment

Comments

@som-snytt
Copy link
Contributor

Minimized code

package app {
  package util {
    class C
  }
  package object util
  class D extends util.C {
    import p._
    println(util.`package`)
    //def g = new util.C    // error
    def f = test
  }
}
package p {
  package util {
    class Nope
  }
  package object util
  object test extends App {
    println(app.util.`package`)
    println(p.util.`package`)
    new app.D
  }
}

Output

app.util.package$@5afa04c
p.util.package$@174d20a
p.util.package$@174d20a

Expectation

The import from p should not shadow a definition from app. Selection in D from util should be ambiguous.

The spec is slightly ambiguous about what a package is: "packages [packagings] are not introduced by a definition".

Therefore, the spec should not say "defined in the same compilation unit" but "introduced" to mean "defined or packaged".

The alternative interpretation is that the spec has nothing to say about package names because a package is not an entity.

scala/bug#11826

@som-snytt
Copy link
Contributor Author

the spec has nothing to say about package names

Actually, https://scala-lang.org/files/archive/spec/2.13/02-identifiers-names-and-scopes.html says

Note that a package definition is taken as lowest precedence...

but it's in the following body of the text, not in the enumeration of precedence levels.

The accompanying example is illustrative.

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

No branches or pull requests

2 participants