Skip to content
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

Possible regression: Ambiguous implicit extension methods error #15656

Closed
KacperFKorban opened this issue Jul 12, 2022 · 2 comments
Closed

Possible regression: Ambiguous implicit extension methods error #15656

KacperFKorban opened this issue Jul 12, 2022 · 2 comments

Comments

@KacperFKorban
Copy link
Member

Compiler version

3.1.1, ... , 3.1.3, 3.2.0-RC1, 3.2.1-RC1-bin-20220711-6efd92d-NIGHTLY

Minimized code

trait Functor[F[_]]:
  extension [A](fa: F[A])
    def void: F[Unit] = ???

given Functor[Option] with {}

given [F[_], X]: Functor[[T] =>> F[X]] with {}

def main =
  val o: Option[Int] = ???
  o.void

Output

[error] ./main.scala:13:3: Found:    (o : Option[Int])
[error] Required: ?{ void: ? }
[error] Note that implicit extension methods cannot be applied because they are ambiguous;
[error] both object given_Functor_Option and given instance given_Functor_F provide an extension method `void` on (o : Option[Int])
[error]   o.void
[error]   ^

Expectation

Should possibly resolve the method from given_Functor_Option.

Interestingly, the following code compiles correctly and resolves the method from given_Functor_Option. (moving the extension method outside of the type class declaration and adding an implicit constraint instead)

trait Functor[F[_]]

extension [F[_]: Functor, A](fa: F[A])
  def void: F[Unit] = ???

given Functor[Option] with {}

given [F[_], X]: Functor[[T] =>> F[X]] with {}

def main =
  val o: Option[Int] = ???
  o.void

Found in #15647

@odersky
Copy link
Contributor

odersky commented Jul 12, 2022

The original code makes no sense anyway. Why do you think it should resolve to the method from given_Functor_Option.?

@KacperFKorban
Copy link
Member Author

Ooooh, right. Those two examples aren't really equivalent.
The method from given_Functor_Option was resolved up until 3.0.2, but I guess that was a bug then.

@griggt griggt removed itype:bug stat:needs triage Every issue needs to have an "area" and "itype" label labels Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants