Skip to content

Clarify spec on precedence of definitions in the same package and imports supplied by the compiler #12513

Closed
scala/scala
#10162
@unkarjedy

Description

@unkarjedy

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

Currently, spec says:

Bindings of different kinds have precedence defined on them:
...
4. Definitions made available by a package clause, but not also defined in the same compilation unit as the reference to them, as well as imports which are supplied by the compiler but not explicitly written in source code, have the lowest precedence.\

It sounds like definitions in the same package and imports supplied by the compiler have the same precedence.

But looks like definitions in the same package have a higher precedence.
Otherwise, I would expect this code to produce some ambiguity error.
But it compiles and shows that definition in the same package is preferred

image

I think we could split spec item 4. into two items 4. and 5.
If you agree I could make a PR

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions