You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Unify scope lookup for companions and default getters
In scala#5700, I fixed a bug in the companion lookup, which ensured
they were defined in the same scope.
The same approach applies well to the lookup of default getters.
You may ask, we can't just use:
```
context.lookupSymbol(name, _.owner == expectedOwner)
```
That doesn't individually lookup the entry in each enclosing
nested scopes, but rather relies on the outer scope delegation
in `Scope.lookupEntry` itself. This in turn relies on the way that
nested scopes share the `elems` table with the enclosing scope:
```
final def newNestedScope(outer: Scope): Scope = {
val nested = newScope
nested.elems = outer.elems
nested.nestinglevel = outer.nestinglevel + 1
...
}
```
If the outer scope is later mutated, in our case by lazily adding
the default getter, the inner scope won't see the new elems.
Context.lookupSymbol will jump immediately jump to search of the
enclosing prefix.
Perhaps a better design would be for the inner scope to retain a
reference to the outer one, rather than just to the head of its
elems linked list at the time the nested scope was created.
0 commit comments