Skip to content

"Ambiguous" imports collide with object definitions #7876

@travisbrown

Description

@travisbrown

minimized code

object foo
object bar

import foo._, bar._

object eq

expectation

This should compile, but instead it fails with this error:

-- [E049] Reference Error: eq.scala:6:0 ----------------------------------------
6 |object eq
  |^
  |Reference to eq is ambiguous
  |it is both imported by import foo._
  |and imported subsequently by import bar._

Explanation
===========
The compiler can't decide which of the possible choices you
are referencing with eq.
Note:
- Definitions take precedence over imports
- Named imports take precedence over wildcard imports
- You may replace a name when imported using
  import scala.{ eq => eqTick }

The same things happen if instead of eq you have a definition explicitly defined on the objects.

If you only have a single eq method import, it compiles just fine. If you replace object eq with trait eq it's also fine.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions