-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Fix #4785: change typing rule for _* args #4787
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
Conversation
0c89b74
to
721c97e
Compare
In expression position, if a tree is of the form `expr: _*`, try to type `expr` as an `Array` and as a `Seq` if there are errors
721c97e
to
5aedeb0
Compare
FWIW, the following code used to find the object Test {
implicit def array: Array[Int] = Array(0)
implicit def seq: Seq[Int] = Seq(0)
def foo(x: Int*) = x
def main(args: Array[String]): Unit = {
println(foo(implicitly: _*))
}
} Any reason to try the Array prototype first? Most of the time I expect users would pass a Seq, so that would be a lot of unnecessary retyping. I also wonder if you could use a union of Array or Seq as the prototype. |
We could try |
Maybe try Array first only for JavaDefined methods? |
Wait, doesn't #4785 imply that this implicit conversion won't exist with 2.13, thus solving the problem? |
No, still there. |
Anyway, relying on an implicit conversion defined in the standard library to typecheck calls to Java methods with repeated arguments seems like a very bad idea to me. What if I compile with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we agreed that we would not support this. I.e. we should allow arrays only for Java varargs.
In other words:
- If it's a Java vararg the argument has to be an array
- If it's a Scala vararg the argument has to be an immutable.Seq.'
On further discussion, I think it's preferable to have automatic conversions for varargs. We already have a conversion from Seq to Array when passing a Seq argument to a Java vararg. We should have a dual conversion from Array to Seq when passing an Array argument to a Scala vararg. I believe the Array-> Seq conversion should make a defensive copy of the array in order to prevent mutations leaking into the vararg. |
Superseded by #5577 |
In expression position, if a tree is of the form
expr: _*
, try to typeexpr
as anArray
and as aSeq
if there are errors