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 implicit values #721

Closed
ashawley opened this issue Nov 18, 2020 · 3 comments · Fixed by #788
Closed

Ambiguous implicit values #721

ashawley opened this issue Nov 18, 2020 · 3 comments · Fixed by #788
Labels

Comments

@ashawley
Copy link
Contributor

Seth ran across an issue in the Scala build when upgrading to ScalaCheck 1.15.1 from 1.14.3 in scala/scala#9301.

Seems it fails to compile because of an ambiguous implicit:

[error] /home/jenkins/workspace/scala-2.13.x-validate-main@2/test/scalacheck/scala/collection/FloatFormatTest.scala:86:17: ambiguous implicit values:
[error]  both method buildableArrayList in object Buildable of type [T]org.scalacheck.util.Buildable[T,java.util.ArrayList[T]]
[error]  and method buildableSeq in object Buildable of type [T]org.scalacheck.util.Buildable[T,scala.collection.Seq[T]]
[error]  match expected type org.scalacheck.util.Buildable[String,C]
[error]     Gen.sequence(bogoparts).map(_.asScala.mkString)
[error]                 ^
[error] /home/jenkins/workspace/scala-2.13.x-validate-main@2/test/scalacheck/scala/collection/IntegralParseTest.scala:123:33: ambiguous implicit values:
[error]  both method buildableArrayList in object Buildable of type [T]org.scalacheck.util.Buildable[T,java.util.ArrayList[T]]
[error]  and method buildableSeq in object Buildable of type [T]org.scalacheck.util.Buildable[T,scala.collection.Seq[T]]
[error]  match expected type org.scalacheck.util.Buildable[Char,C]
[error]     val sequenced = Gen.sequence(listOfGens)
[error]                                 ^
[error] two errors found
@ashawley
Copy link
Contributor Author

The only thing I can think of is the addition of buildableSeq as part of #575.

@SethTisue
Copy link
Member

SethTisue commented Nov 20, 2020

I worked around it as follows:

-    import scala.collection.JavaConverters._
-
-    Gen.sequence(bogoparts).map(_.asScala.mkString)
+    // type annotation shouldn't be necessary? see typelevel/scalacheck#721
+    Gen.sequence[List[String], String](bogoparts).map(_.mkString)

-    val sequenced = Gen.sequence(listOfGens)
-    sequenced.map(l => scala.collection.JavaConverters.asScalaBuffer(l).mkString)
+    // type annotation shouldn't be necessary? see typelevel/scalacheck#721
+    Gen.sequence[List[Char], Char](listOfGens).map(_.mkString)

I don't know why JavaConverters dropped out of the picture, but perhaps it's a clue? 🤷

@ashawley
Copy link
Contributor Author

I presume the JavaConverters is just a consequence of the domain of the test.

Not a lot of people use Gen.sequence but it seems like we need to fix the ambiguity. I'm not sure if we need both buildables or not. Fixing it would be a binary compatible change. This would be to fix a bug, so that's ok?

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.

2 participants