Skip to content

Ambiguous reference error message does not know about rule change in #8622 #12682

Closed
@lrytz

Description

@lrytz
object C {
  def m(x: Int) = 1
  object T extends K {
    val x = m(1)
  }
}
class K {
  def m(i: Int) = 2
}

gives

-- [E049] Reference Error: Test.scala:4:12 -------------------------------------
4 |    val x = m(1)
  |            ^
  |            Reference to m is ambiguous,
  |            it is both defined in object C
  |            and inherited subsequently in object T

Explanation
===========
The compiler can't decide which of the possible choices you
are referencing with m: A definition of lower precedence
in an inner scope, or a definition with higher precedence in
an outer scope.
Note:
 - Definitions in an enclosing scope take precedence over inherited definitions
 - Definitions take precedence over imports
 - Named imports take precedence over wildcard imports
 - You may replace a name when imported using
   import scala.{ m => mTick }

The -explain message even says "Definitions in an enclosing scope take precedence over inherited definitions".

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions