Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
lrytz opened this issue Jun 2, 2021 · 5 comments · Fixed by #16137
Closed

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

lrytz opened this issue Jun 2, 2021 · 5 comments · Fixed by #16137
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc exp:novice help wanted itype:bug Spree Suitable for a future Spree
Milestone

Comments

@lrytz
Copy link
Member

lrytz commented Jun 2, 2021

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".

@lrytz lrytz added the itype:bug label Jun 2, 2021
@smarter
Copy link
Member

smarter commented Jun 2, 2021

This was intentionally changed in #8622, looks like the error message needs to be updated.

@smarter smarter added the area:reporting Error reporting including formatting, implicit suggestions, etc label Jun 2, 2021
@lrytz
Copy link
Member Author

lrytz commented Jun 2, 2021

👍

Ftr, Scala 2 actually resolves m to K.m: https://www.scala-lang.org/files/archive/spec/2.11/02-identifiers-names-and-scopes.html

@smarter smarter changed the title Invalid ambiguous reference error Ambiguous reference error message does not know about rule change in #8622 Jun 2, 2021
@som-snytt
Copy link
Contributor

I intended to follow up Scala 2 at scala/scala#8839

@odersky
Copy link
Contributor

odersky commented Jun 2, 2021

The error message could be clearer, but is correct. There is "A definition of lower precedence (i.e. inheritance)
in an inner scope, and a definition with higher precedence (i.e. definition) in an outer scope.".

@anatoliykmetyuk anatoliykmetyuk added the Spree Suitable for a future Spree label Jul 20, 2021
@odersky
Copy link
Contributor

odersky commented Oct 3, 2021

I close since no better diagnostics was forthcoming.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:reporting Error reporting including formatting, implicit suggestions, etc exp:novice help wanted itype:bug Spree Suitable for a future Spree
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants