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
Predef.implicitly TODO comment #11124
Comments
I am very much in favor of this change. It also prevents loss of type information. |
🤔 object A {
def x1[A](implicit a: A): A = a
@inline def x2[A](implicit a: A): A = a
def x3[A](implicit a: A): a.type = a
@inline def x4[A](implicit a: A): a.type = a
implicit val i = 42
def main(): Unit = {
x1[Int]
x2[Int]
x3[Int]
x4[Int]
}
}
|
|
Would be interesting to do this change and see what happens to the community build. Same thing with |
(Wait, I misunderstood something) |
What is the problem with the bytecode you posted above? |
The |
The inliner works on the bytecode level, on erased types, so the change doesn't matter there. It can make a difference in constant folding, maybe elsewhere
|
Maybe we should also change following similar methods.
|
@xuwei-k what would that gain us in those cases? The rationale for making the change in the case of |
Implementing this in Scala 2 will require fixing the compiler to be a bit more tolerant when using a dependent method as a function (it should just widen the dependent part), from https://github.com/smarter/scala/tree/precise-id: [error] /home/smarter/opt/scala/src/library/scala/StringContext.scala:114:54: polymorphic expression cannot be instantiated to expected type;
[error] found : [A](x: A)x.type (with underlying type [A](x: A)x.type)
[error] required: String => String
[error] def raw(args: Any*): String = standardInterpolator(identity, args, parts)
[error] ^
[error] /home/smarter/opt/scala/src/library/scala/collection/ArrayOps.scala:1209:39: method with dependent type (x: A)x.type cannot be converted to function value
[error] def distinct: Array[A] = distinctBy(identity)
[error] ^ |
Fixes scala/bug#11124 Breaks because scalac doesn't like the dependent result type.
Let's consider this during 2.14 dev, since it has knock-on effects as mentioned by smarter. |
Here's what I tried to improve type inference, but this broke a massive number of quasiquote-related tests, and we're out of time for RC1:
I also tried not changing the compiler, but a slightly more sneaky signature for
this runs into other compiler bugs (the evidence parameter may be private, and the result type is not properly widened to avoid depending on it) 😓 |
For the record, I tried one more (perhaps too hacky) compromise, but still too many macro tests break (and I have no idea how to even approach fixing them)
Test failures:
|
https://github.com/scala/scala/blob/v2.13.0-M5/src/library/scala/Predef.scala#L214
Should we just add
e.type
? or remove TODO comment if incorrect?The text was updated successfully, but these errors were encountered: