Skip to content
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

Import does not respect level 1 (one) binding precedence #11826

Open
som-snytt opened this issue Dec 13, 2019 · 0 comments
Open

Import does not respect level 1 (one) binding precedence #11826

som-snytt opened this issue Dec 13, 2019 · 0 comments

Comments

@som-snytt
Copy link

@som-snytt som-snytt commented Dec 13, 2019

util.C is available by package clause and is defined in the same file as the usage, so it is a "level 1" binding. The import cannot shadow it. So the reference to util should be ambiguous. The import also incorrectly shadows if moved one level up.

Note that the name up for grabs is the required member of util, util.C or as shown below, the package object. Since "packages [packagings] are not introduced by a definition", and name bindings are defined for definitions, we can't actually speak of the binding of util, but of the name C.

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`)
    println(new app.D)
  }
}

Output is

app.util.package$@67b467e9
p.util.package$@5c072e3f
p.util.package$@5c072e3f
app.D@149494d8

but commenting the import

app.util.package$@67b467e9
p.util.package$@5c072e3f
app.util.package$@67b467e9
app.D@149494d8

Expected:

package object app {
  val util = 42
  class D {
    import p._
    println(util)
  }
}
package object p {
  val util = 42
  object test extends App {
    println(new app.D)
  }
}

Result:

t11826.scala:5: error: reference to util is ambiguous;
it is both defined in package object app and imported subsequently by
import p._
    println(util)
            ^
@som-snytt som-snytt changed the title I can't get past chapter 2 of the spec Import does not respect level 1 (one) binding precedence Dec 20, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
1 participant
You can’t perform that action at this time.