Closed scabug closed 10 years ago
Imported From: https://issues.scala-lang.org/browse/SI-8559?orig=1 Reporter: @paulp Affected Versions: 2.10.4, 2.11.0 See #2548
@paulp said: I should receive partial credit on some of his. Look at #8338 for instance. I reopened it after it was closed not-a-bug, and it was again closed not-a-bug. That has to be reflected in my stats or the whole thing is a sham.
@retronym said: We've got an imported symbol in the inner scope (s.util) , and a defined symbol (bob.util) in the outer scope. What are the binding precedences of each of these?
1. Definitions and declarations that are local, inherited, or made available by a package clause in the same compilation unit where the definition occurs have highest precedence.
2. Explicit imports have next highest precedence.
3. Wildcard imports have next highest precedence.
4. Definitions made available by a package clause not in the compilation unit where the definition occurs have lowest precedence.
Intuition suggests that bob.util
should have precedence #1, as syntactically it is defined in the same source file as package bob. But because packages are open, it could also be defined an any number of other source files. As such, packages are considered to be source-file-less drifters, and that shunts the precedence of the defSym
down to 4.
In this case, shadowing is as specced:
A binding in some inner scope shadows bindings of lower precedence in the same scope as well as bindings of the same or lower precedence in outer scopes.
See also #2458 / https://github.com/retronym/scala/tree/ticket/2458, in which I have a fix for the arbiter of this rule. I'll add a task to that ticket to add a clarification to the spec along these lines.
@paulp said: Take that, alefas.
@som-snytt said: I enshrined the example. I hope they accept https://github.com/scala/scala/pull/5151/files
It has to be a bug? Oh well I also must have the record for "Not a Bug", like how home run records can be accompanied by strikeout and walk records.
This one however compiles, and when run indicates that package util was successfully shadowed.