-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Arrays and Repeated arguments in 2.13 and future Dotty version #4785
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
I don’t think scalac has special cased the typing rule for splicing arrays as multiple parameters. If you write |
class Test {
def bar(xs: String*) = 1
def foo(xs: Array[String]) = {
bar(xs: _*)
java.nio.file.Paths.get("", xs: _*)
}
} Simplified output from
@julienrf As you can see typer does not introduce any implicit conversion from |
You’re right. We have a deprecated implicit conversion but it’s used only when one wants to coerce an |
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
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
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
We concluded that if |
I have opened scala/bug#11024 |
We typecheck them without expected type to avoid relying on the implicit conversion from Array to Seq defined in Predef. ElimRepeated does the necessary adaptations (i.e. seqToArray and arrayToSeq conversions).
We typecheck them without expected type to avoid relying on the implicit conversion from Array to Seq defined in Predef. ElimRepeated does the necessary adaptations (i.e. seqToArray and arrayToSeq conversions).
We typecheck them without expected type to avoid relying on the implicit conversion from Array to Seq defined in Predef. ElimRepeated does the necessary adaptations (i.e. seqToArray and arrayToSeq conversions).
Fix #4785: Change typing rule for wildcard star args
Starting with Scala 2.13 the default
Seq
type isimmutable.Seq
. This change apply to repeated arguments:However, it is still possible to pass an Array where repeated arguments are expected. This is a requirement for java interoperability.
In Dotty, given
foo: _*
,foo
must be a subtype ofSeq
. Iffoo
is an array, then an implicit conversion is applied (i.e.Predef.wrapXXXArray
). We don't need to special case arrays in typer but latter (in ElimRepeated) we have to revert the conversion if the array is used as a repeated arguments of a java defined method. E.g.The current implicit conversions defined in
Predef
returns amutable.Seq
.How do we solve this problem in the future when Dotty switch its default
Seq
type toimmutable.Seq
instead ofcollection.Seq
? Here are my thoughts, either:DottyPredef
(orPredef
?) fromArray
toimmutable.Seq
.I think
scalac
does 2). @adriaanm, any thoughts on this?The text was updated successfully, but these errors were encountered: