- 
                Notifications
    You must be signed in to change notification settings 
- Fork 21
Closed
Description
Reproduction steps
Scala version: (Is the bug only in Scala 3.x? If so, report it at https://github.com/lampepfl/dotty/issues/new/choose instead.)
//> using scala "2.13.8"
package foo {
  package object syntax {
    implicit class BarOps1(a: Any) {
      def bar(x: Int): String = ???
    }
    implicit class BarOps2(a: Any) {
      private[syntax] def bar(x: Int): String = ???
    }
  }
}
import foo.syntax._
object Main {
  def main(args: Array[String]): Unit = {
    val a = new Object
    a.bar(42)
  }
}
Problem
[error] ./bug.scala:20: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 BarOps1 in package syntax of type (a: Any): foo.syntax.package.BarOps1
[error]  and method BarOps2 in package syntax of type (a: Any): foo.syntax.package.BarOps2
[error]  are possible conversion functions from a.type to ?{def bar(x$1: ? >: Int(42)): ?}
[error]     a.bar(42)
[error]     ^
[error] ./bug.scala:20:5: value bar is not a member of Object
[error]     a.bar(42)
[error]     ^^^^^
It's surprising that the conversion is ambiguous, since BarOps2 should not have publicly visible methods. Note also that changing to private will solve the problem.
Credit to @BalmungSan for identifying the issue while working on typelevel/cats#4183.
Metadata
Metadata
Assignees
Labels
No labels