-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Ambiguous implicit error involving implicits defined in the companions of classes where one is a subclass of another (works in Scala 2) #12125
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
It's fairly similar to #12123 actually, you're doing an implicit search on trait Op[+T, U] |
Thanks @smarter. I can't do that because Op is actually more like trait Op[T, U] {
def apply(t: T, u: U)
} In Scala 2, I think the preference for dvOp comes via the Relative Weighting rule. (6.26.3)
https://scala-lang.org/files/archive/spec/2.13/06-expressions.html#overloading-resolution Is that removed from Scala 3? I couldn't find the spec. |
(In fact, the reason I believe it different from 12123 is precisely this rule.) Note that it works fine if I remove the Ops traits, so I think that the definition of "defined in" is maybe change? I.e. this works fine, and it shouldn't by your logic?
|
Ah, you mean this rule in particular?
That rule still exists though it's been slightly modified, see point 6 of http://dotty.epfl.ch/docs/reference/changed-features/implicit-resolution.html So maybe your original example should work indeed, dvOp and vOp are not declared in DenseVector and Vector, but they're clearly members of these classes. Reopening. |
Great thank you!
…On Fri, Apr 16, 2021, 1:26 PM Guillaume Martres ***@***.***> wrote:
Ah, you mean this rule in particular?
if AAA is defined in a class or object which is derived from the class or
object defining BBB,
That rule still exists though it's been slightly modified, see point 6 of
http://dotty.epfl.ch/docs/reference/changed-features/implicit-resolution.html
So maybe your original example should work indeed, dvOp and vOp are not
declared in DenseVector and Vector, but they're clearly members of these
classes. Reopening.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#12125 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACLIMMCCBBEE5X73X6MY3TJCMOFANCNFSM43CDQH5Q>
.
|
It runs afoul of the condition in point 8 of http://dotty.epfl.ch/docs/reference/changed-features/implicit-resolution.html.
It works if |
And I don't see how this would work with Scala 2's spec either. There is no relationship between DenseVectorOps and VectorOps which is where the implicits are defined. So this looks like a Scala 2 bug to me. |
But there is a relationship between Vector and DenseVector? Does "defined
in" mean literally the declaration is in the template, as opposed to being
a member?
…On Sun, Apr 18, 2021, 4:01 AM odersky ***@***.***> wrote:
And I don't see how this would work with Scala 2's spec either. There is
no relationship between DenseVectorOps and VectorOps which is where the
implicits are defined. So this looks like a Scala 2 bug to me.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#12125 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAACLIIJXNVCGSKOHHNDLDDTJK3YZANCNFSM43CDQH5Q>
.
|
or at least, it's changed from Scala 2.
First I want to say that Scala 3 is turning out to be a very nice language and I’m excited for what we can do with it. Thank you.
I am in the process of trying to get Breeze compiling under Scala 3. There is a common pattern in Breeze in how I organize implicits, where for a class XVector I have a trait XVectorOps with a bunch of implicits in it that object XVector extends. Usually these are stacked a bit. In Scala 2 this all worked fine, but in Scala 3, this leads to problems in the case where there is a subtype relationship between different XVectors.
Compiler version
3.0.0-RC2
Minimized code
This is a minimized example that compiles fine in Scala 2 but does not work in Scala 3:
Output
Expectation
This compiles fine in Scala 2, and if I remove the XVectorOps classes and inline them into the companions directly this compiles fine in Scala 3, but the inheritance trips it up.
Is this intentional?
The text was updated successfully, but these errors were encountered: