Skip to content

Ambiguous reference yields wrong error message #9882

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
rjolly opened this issue Sep 25, 2020 · 3 comments
Closed

Ambiguous reference yields wrong error message #9882

rjolly opened this issue Sep 25, 2020 · 3 comments

Comments

@rjolly
Copy link
Contributor

rjolly commented Sep 25, 2020

trait SemiGroup[T]:
  def combine(x: T, y: T): T

trait Monoid[T] extends SemiGroup[T]:
  def unit: T

class A

given Monoid[A]:
  def combine(x: A, y: A) = ???
  def unit = ???

class B

given Monoid[B]:
  def combine(x: B, y: B) = ???
  def unit = ???

import given_Monoid_A.combine
import given_Monoid_B.combine
val a = new A
val b = new B
println(combine(b, b))
        ^^^^^^^
      Reference to combine is ambiguous,
      it is both imported by name by import dotty.DottyPredef.{...}
      and imported by name subsequently by import given_Monoid_B.combine
@som-snytt
Copy link
Contributor

Duplicates #9803

@rjolly
Copy link
Contributor Author

rjolly commented Sep 26, 2020

Closing the issue then. For the record, I don't understand why this has to be ambiguous, whereas the code below is not.

class A
class B

object C:
  def combine(x: A, y: A) = ???
  def combine(x: B, y: B) = ???

import C._
val a = new A
println(combine(a, a))

@rjolly rjolly closed this as completed Sep 26, 2020
@som-snytt
Copy link
Contributor

The latter is an overloaded symbol C.combine, where an alternative is picked by overload resolution.

The former is an ambiguity in name binding, because there is no basis for preferring one binding over the other.

This comes up periodically, where the expectation is that a multiple-binding could be treated like an overloaded symbol, much as multiple candidates in an implicit search are resolved using the same procedure as overload resolution.

I think the expectation is that intertwining name resolution and typechecking more than the minimum would invite cycles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants