-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Spurious implicit argument ambiguity #7999
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
Comments
Isn’t it because |
@julienrf I guess that explains why I can't reproduce it with a custom |
Might also be worth noting that in the original context the error message actually says that the supposed ambiguous instances both match [error] -- Error: /home/travis/code/projects/cats/tests/src/test/scala/cats/tests/KleisliSuite.scala:310:24
[error] 310 | } yield (k1, k2, k3)
[error] | ^
[error] |ambiguous implicit arguments: both method catsStdMonadForFunction1 in trait Function1Instances and value catsStdInstancesForList in trait ListInstances match type cats.Functor[List] of parameter F of method map in class Kleisli |
Right, |
If the |
It's not more specific since |
Here's a minimization: class Inv[A]
class X
class Y extends X
object Test {
implicit def impX: Inv[X] = ???
implicit def impY: Inv[Y] = ???
def foo[T](x: T)(implicit inv: Inv[T]): Inv[T] = ???
def wrap[S](y: Inv[S]): Any = ???
val y: Y = ???
foo(y) // OK
wrap(foo(y)) // ambiguous
} Before doing an implicit search, we need to instantiate some of the type variables involved (because otherwise we're likely to run into ambiguity) but we can't instantiate all of them (some of the type variables might be resolved by the implicit search itself, cf https://milessabin.com/blog/2011/07/16/fundeps-in-scala/). The heuristic we use currently instantiate all type variables which appear in a prefix of the current expression (https://github.com/lampepfl/dotty/blob/9322e8c3dad176c948583c5da262f77b11ec75c6/compiler/src/dotty/tools/dotc/typer/Inferencing.scala#L200-L208), but this doesn't work with wrap[?S](foo[?T](y))
where
?T := ?S
?S >: Y at this point we search for uninstantiated type variables in the expression (On a side note, I think the current logic where we traverse an expression to find type variables to instantiate is perhaps too complicated, see #4742 (comment) for an alternative approach I have yet to properly explore) |
For what it's worth I'm seeing something similar in another place in the Cats tests, where this code: List(1, 2, 3).traverse(i => Const.of[List[Int]](List(i))) Has the inferred type |
minimized code
Compilation output
expectation
This is another attempt to minimize something I'm running into in the Cats tests. As in #7993 the Scala 2 equivalent compiles as expected.
It might be worth noting that if
instance1
isTC[Option]
or evenTC[[x] =>> x => Int]
, Dotty has no problem with this. I tried minimizing with my owntrait Func[-A, +B]
but couldn't get it to error.The text was updated successfully, but these errors were encountered: