-
Notifications
You must be signed in to change notification settings - Fork 21
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
Invariant implicit definition is not picked up for its covariant supertype implicit parameter #12231
Comments
By the way, in incremental builds the compiler doesn't notice that |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
But |
Yes, this example didn't work only due to a typo, but I already got one without it! So sorry, you should have been quicker with closing! |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
I guess this is why companions are defined together, I mean close together. It suggests an alternative syntax would have been wise; they must have considered alternatives. A linter could notice names that are too close and also companions that aren't close enough. There is a lint at the office about overloads must be textually contiguous. |
I'm reminded of this old photo of mine: https://www.flickr.com/photos/tisue/5466211519 |
I think it's the first time in my ~10y of working with scala that I made such a mistake: note that normally objects are there to put other things than implicits in and, when referencing them explicitly, the typos are easier to spot. |
I added nested companion to my feature request for "export this._". I included "anonymous companion". Don't worry, they never adopt my suggestions. To be fair, sometimes they'll accept a PR and then either revert it or ignore it. The flickr stream seems to be bottomless. I think I'll pause now and rest. I suddenly feel very cold. I wonder if "Want a X but can't quit your Y?" is a meme? That initial picture also works for "anonymous companion." |
Now I saw the typo in the original issue 🙈 - when debugging implicit issues you might want to enable [info] ~/scratch/src/main/scala/ImplicitFun.scala:24:15: ImplicitFun.this.Invariants.invariant is not a valid implicit value for ImplicitFun.Invariant[T] because:
[info] hasMatchingSymbol reported error: diverging implicit expansion for type ImplicitFun.Invariant[T]
[info] starting with method invariant in object Invariants
[info] implicitly[Covariant[Option[Int]]]
[info] ^
[info] ~/scratch/src/main/scala/ImplicitFun.scala:24:15: ImplicitFun.this.Invariants.invariant is not a valid implicit value for ImplicitFun.Covariant[Option[Int]] because:
[info] hasMatchingSymbol reported error: ambiguous implicit values:
[info] both value int in object Implicits of type ImplicitFun.Invariant[Int]
[info] and value short in object Implicits of type ImplicitFun.Invariant[Short]
[info] match expected type ImplicitFun.Invariant[T]
[info] implicitly[Covariant[Option[Int]]]
[info] You can minimise a bit by removing |
More specifically there is a function that retracts type parameters that were instantiated to |
Glad do hear it works in scala 3, seems like a might tighter design, I am starting to look hopeful. |
This is a known issue of implicits in Scala 2 - |
Is there a ticket of record on that? I'd like to close this a duplicate, especially since the history here is now confusing to follow because of the class naming red herring. But to close it as a duplicate, there should be something it's a duplicate of :-) |
Isn't this fixed by scala/scala#6037? Available under |
Let's see what Dotty says!
|
There is no contravariance involved here |
when I "remove the covariant definition in object how do I get the "ambiguous implicit values" error instead? which is the "true" error that this bug is about? |
with
the original issue is about which instance is selected and printed not about what compiles |
Strongly agreeing |
reproduction steps
using Scala 2.13.3,
prints:
If I remove the covariant definition in
object Covariant
, I get a compiler error of missing implicit, with the following hint:Original report, for amusement purposes (user error due to a typo):
prints:
problem
I would expect
Invariants.invariant[T]
in place ofCovariants.covariant[Int]
The text was updated successfully, but these errors were encountered: