Skip to content

Possible regression: Ambiguous implicit extension methods error #15656

Closed
@KacperFKorban

Description

@KacperFKorban

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions