bug icon indicating copy to clipboard operation
bug copied to clipboard

package-private methods still ambiguate implicit conversions

Open armanbilge opened this issue 3 years ago • 0 comments

Reproduction steps

//> using scala "2.13.11-bin-f3bd333"

package foo {

  trait Baz[A]
  object Baz {
    implicit def instance[A]: Baz[A] = ???
  }

  package syntax {
    object all {
      implicit def ops1[A: Baz](a: A): BarOps1 = new BarOps1(a)
      implicit def ops2[A: Baz](a: A): BarOps2 = new BarOps2(a)
    }

    class BarOps1(val a: Any) extends AnyVal {
      def bar(x: Int): String = ???
    }

    class BarOps2(val a: Any) extends AnyVal {
      private[syntax] def bar(x: Int): String = ???
    }
  }
}

import foo.syntax.all._

object Main {
  def main(args: Array[String]): Unit = {
    val a = new Object
    a.bar(42)
  }
}

Problem

[error] ./bug.scala:31:5: type mismatch;
[error]  found   : a.type (with underlying type Object)
[error]  required: ?{def bar(x$1: ? >: Int(42)): ?}
[error] Note that implicit conversions are not applicable because they are ambiguous:
[error]  both method ops1 in object all of type [A](a: A)(implicit evidence$1: foo.Baz[A]): foo.syntax.BarOps1
[error]  and method ops2 in object all of type [A](a: A)(implicit evidence$2: foo.Baz[A]): foo.syntax.BarOps2
[error]  are possible conversion functions from a.type to ?{def bar(x$1: ? >: Int(42)): ?}
[error]     a.bar(42)
[error]     ^
[error] ./bug.scala:31:5: value bar is not a member of Object
[error]     a.bar(42)
[error]     ^^^^^

This reproducer is a revival of https://github.com/scala/bug/issues/12578, which was solved as originally reported via https://github.com/scala/bug/issues/11787 / https://github.com/scala/scala/pull/9999. But unfortunately that fix did not help in https://github.com/typelevel/cats/issues/4244. It seems that adding the typeclass constraint breaks it.

armanbilge avatar Oct 15 '22 23:10 armanbilge