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

package-private methods still ambiguate implicit conversions #12666

Closed
armanbilge opened this issue Oct 15, 2022 · 2 comments · Fixed by scala/scala#10191
Closed

package-private methods still ambiguate implicit conversions #12666

armanbilge opened this issue Oct 15, 2022 · 2 comments · Fixed by scala/scala#10191
Assignees
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) has PR implicit
Milestone

Comments

@armanbilge
Copy link

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 #12578, which was solved as originally reported via #11787 / scala/scala#9999. But unfortunately that fix did not help in typelevel/cats#4244. It seems that adding the typeclass constraint breaks it.

@som-snytt
Copy link

som-snytt commented Oct 16, 2022

The implicit section is skipped in the relevant code and the previous fix is also skipped. I will PR.

It occurs to me that we shouldn't ask for minimal reproducers but minimal use cases.

@som-snytt som-snytt self-assigned this Oct 16, 2022
@SethTisue SethTisue added this to the 2.13.11 milestone Oct 16, 2022
@SethTisue
Copy link
Member

SethTisue commented Oct 16, 2022

It occurs to me that we shouldn't ask for minimal reproducers but minimal use cases

Dale and I often note this — that one always wants an absolutely minimal version, but it's also often good to have something a bit more full that illustrates programmer intent and demonstrates how the issue might arise in practice

@lrytz lrytz added the fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) label Nov 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fixed in Scala 3 This issue does not exist in the Scala 3 compiler (https://github.com/lampepfl/dotty/) has PR implicit
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants