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

ambiguous contains_ syntax #4244

Closed
armanbilge opened this issue Jun 20, 2022 · 10 comments · Fixed by #4320
Closed

ambiguous contains_ syntax #4244

armanbilge opened this issue Jun 20, 2022 · 10 comments · Fixed by #4320
Labels

Comments

@armanbilge
Copy link
Member

Frustrating I can't make a small reproducer, but here it is in the wild.
https://github.com/gemini-hlsw/explore/runs/6928906317?check_suite_focus=true#step:7:56

The problem is that:

def contains_(v: A)(implicit ev: Eq[A], F: UnorderedFoldable[F]): Boolean =

conflicts with

private[syntax] def contains_(v: A, eq: Eq[A], F: Foldable[F]): Boolean =

This is related to scala/bug#12578.

I thought we worked through it in #4183 since I linked it in that ticket, but seems there are still problems in some situations 🤔

@armanbilge armanbilge added the bug label Jun 20, 2022
@armanbilge
Copy link
Member Author

armanbilge commented Jun 20, 2022

Aha, here's a reproducer. The issue seems to be when using it as a lambda.

//> using scala "2.13.8"
//> using lib "org.typelevel::cats-core::2.8.0"

import cats.syntax.all._

object Test {
  def main(args: Array[String]): Unit = println(List("a").map(List("a").contains_))
}
[error] ./bug.scala:7:63: type mismatch;
[error]  found   : List[String]
[error]  required: ?{def contains_: ?}
[error] Note that implicit conversions are not applicable because they are ambiguous:
[error]  both method catsSyntaxFoldOps in trait FoldableSyntax of type [F[_], A](fa: F[A])(implicit evidence$2: cats.Foldable[F]): cats.syntax.FoldableOps[F,A]
[error]  and method catsSyntaxUnorderedFoldableOps in trait UnorderedFoldableSyntax of type [F[_], A](fa: F[A])(implicit evidence$1: cats.UnorderedFoldable[F]): cats.syntax.UnorderedFoldableOps[F,A]
[error]  are possible conversion functions from List[String] to ?{def contains_: ?}
[error]   def main(args: Array[String]): Unit = println(List("a").map(List("a").contains_))
[error]                                                               ^^^^^^^^^
[error] ./bug.scala:7:63: value contains_ is not a member of List[String]
[error] did you mean contains?
[error]   def main(args: Array[String]): Unit = println(List("a").map(List("a").contains_))
[error]                                                               ^^^^^^^^^^^^^^^^^^^

@armanbilge
Copy link
Member Author

Rewriting as contains_(_) fixes it.

@armanbilge armanbilge added this to the 2.9.0 milestone Jun 20, 2022
@joroKr21
Copy link
Member

joroKr21 commented Jun 20, 2022

I guess it has to be fixes in the compiler - it works in Scala 3.
I didn't realise that it works when not treated as a lambda.

@armanbilge
Copy link
Member Author

armanbilge commented Jun 20, 2022

I didn't realise that it works when not treated as a lambda.

It does but only because we rewrote the argument list to be (_, _, _) instead of (_)(implicit _, _) precisely to try and avoid this issue.

@joroKr21
Copy link
Member

Oh ok I see - it's a trick that changed the method signature but not binary compatibility.

@armanbilge
Copy link
Member Author

Nobody else has complained, this is annoying to fix, and there's an easy workaround. I'm going to put this on the backlog.

@armanbilge armanbilge removed this from the 2.9.0 milestone Oct 9, 2022
@matthughes
Copy link
Contributor

Came across this a bunch today when I upgraded to 2.8.0 on 2.13.8. Hope to upgrade to Scala 3 soon with this project but just FYI.

@armanbilge
Copy link
Member Author

Darn, just when I thought I got away with it! Thanks for letting us know.

@mahe-ymc
Copy link

Came across this a bunch today when I upgraded to 2.8.0 on 2.13.8. Hope to upgrade to Scala 3 soon with this project but just FYI.

Similar here. Just fyi, workaround is easy enough.

@armanbilge
Copy link
Member Author

I opened scala/bug#12666 with a minimizer of this issue. Also, I might have an idea to solve it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants