-
Notifications
You must be signed in to change notification settings - Fork 21
Inconsistent resolution of implicits #10376
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
No one thinks this is a bug? I had no replies on the Scala user list either. |
The reason that the first compiles and the second doesn't is that the standard library provides an implicit conversion from
Thus the precondition for your implicit def |
No. I expect How do you explain that, if I replace |
See also discussion at: https://users.scala-lang.org/t/implicits-resolution/981 |
I experienced similar brokeness with the following simple example: import scala.util.Try
implicit class MyOption[+A](opt: Option[A]){
def orElse[B >: A](alternative: => Try[B]): Option[B] = opt.orElse(alternative.toOption)
}
Option(1) orElse Try(2) Intellij IDEA linter says everything is all right, however the compiler gives
(same happens when analogously overwriting According to language specs http://scala-lang.org/files/archive/spec/2.12/07-implicits.html#views point 3) this should work, but doesn't apparently. So this is a bug, isn't it? Is this the same issue?, or should I open a new one? |
Agreed. It looks like the same behavior, inconsistent with the specs. I had another compiler bug, somewhat related, recently resolved by @som-snytt . He seems to know his stuff. I wish he could have a look at this one too. |
@schlichtanders I think you encountered this other related issue: #9523 |
Is it fixed in Dotty? |
but
|
The idea is to lift an implicit conversion from
A
toB
into one fromC[A]
toC[B]
. LetA
beInt
andB
beBigInt
:The expression
X + x
compiles fine: argumentx
is lifted into aC[BigInt]
. However,x + X
does not compile (x
is not lifted as a target). It seems to me that it should work.Moreover, the expression
x + X
can be compiled if:+
method is removed from classC
(no overloading), or+
method is given an implementation in theBase
class instead of being abstract, then overridden in classC
.I don't think the specs say anything about overloading or abstract/concrete having such an impact on how implicits are resolved, making this behavior buggy (or at least very mysterious).
This is observed in 2.12.2.
The text was updated successfully, but these errors were encountered: