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

Regression in armanbilge/schrodinger for implicit search #20344

Closed
WojciechMazur opened this issue May 6, 2024 · 0 comments · Fixed by #20368
Closed

Regression in armanbilge/schrodinger for implicit search #20344

WojciechMazur opened this issue May 6, 2024 · 0 comments · Fixed by #20368
Labels
area:implicits related to implicits itype:bug regression This worked in a previous version but doesn't anymore

Comments

@WojciechMazur
Copy link
Contributor

Based on OpenCB failure in armanbilge/schrodinger - builds logs

Compiler version

Last good release: 3.5.0-RC1-bin-20240429-e2c456f-NIGHTLY
First bad release: 3.5.0-RC1-bin-20240501-e6bc130-NIGHTLY
Bisect points to 0890e7a

Minimized code

trait Monad[F[_]] extends Invariant[F]

trait Invariant[F[_]]
object Invariant:
  implicit def catsInstancesForList: Monad[List] = ???
  implicit def catsInstancesForVector: Monad[Vector] = ???
  
trait Shrink[T]
object Shrink extends ShrinkLowPriorityImplicits:
  trait Buildable[T,C] 
  implicit def shrinkContainer[C[_],T](implicit v: C[T] => Traversable[T], s: Shrink[T], b: Buildable[T,C[T]]): Shrink[C[T]] = ???
trait ShrinkLowPriorityImplicits:
  implicit def shrinkAny[T]: Shrink[T] = ???
  
trait Distribution[F[_], -P, X] extends (P => F[X])
type GenBeta[A, B, X] = [F[_]] =>> Distribution[F, Beta.Params[A, B], X]
type Beta[R] = [F[_]] =>> GenBeta[R, R, R][F]

object Beta:
  trait Params[+A, +B]
trait BetaInstances:
  given schrodingerRandomBetaForDouble[F[_]: Monad]: Beta[Double][F] = ???

object all extends BetaInstances

@main def Test = 
  import all.given
  summon[Shrink[Beta.Params[Double, Double]]]

Output

[error] No best given instance of type Shrink[Beta.Params[Double, Double]] was found for parameter x of method summon in object Predef.
[error] I found:
[error] 
[error]     Shrink.shrinkContainer[[B] =>> Beta.Params[Double, B], Double](
[error]       all.schrodingerRandomBetaForDouble[F](
[error]         /* ambiguous: both method catsInstancesForList in object Invariant and method catsInstancesForVector in object Invariant match type Monad[F] */
[error]           summon[Monad[F]]
[error]       ),
[error]     Shrink.shrinkAny[Double],
[error]       /* missing */summon[Shrink.Buildable[Double, Beta.Params[Double, Double]]])
[error] 
[error] But both method catsInstancesForList in object Invariant and method catsInstancesForVector in object Invariant match type Monad[F].
[error]   summon[Shrink[Beta.Params[Double, Double]]]
[error]                                              ^
Error compiling project (Scala 3.5.0-RC1-bin-20240502-05354ba-NIGHTLY, JVM (17))

Expectation

Should compile

@WojciechMazur WojciechMazur added itype:bug area:implicits related to implicits regression This worked in a previous version but doesn't anymore labels May 6, 2024
@mbovel mbovel self-assigned this May 7, 2024
odersky added a commit to dotty-staging/dotty that referenced this issue May 8, 2024
This reverts one part of scala#20261. When we fail with both an ambiguity on one implicit argument and another error on another argument we prefer the other error. I added a comment why this is needed.

Fixes scala#20344
@mbovel mbovel removed their assignment May 8, 2024
odersky added a commit that referenced this issue May 8, 2024
#20368)

This reverts one part of #20261. When we fail with both an ambiguity on
one implicit argument and another error on another argument we prefer
the other error. I added a comment why this is needed.

Fixes #20344
WojciechMazur pushed a commit that referenced this issue Jul 6, 2024
This reverts one part of #20261. When we fail with both an ambiguity on one implicit argument and another error on another argument we prefer the other error. I added a comment why this is needed.

Fixes #20344

[Cherry-picked 863077c]
WojciechMazur pushed a commit that referenced this issue Jul 6, 2024
This reverts one part of #20261. When we fail with both an ambiguity on one implicit argument and another error on another argument we prefer the other error. I added a comment why this is needed.

Fixes #20344

[Cherry-picked 863077c]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:implicits related to implicits itype:bug regression This worked in a previous version but doesn't anymore
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants