Skip to content

Fix #4785: Change typing rule for wildcard star args #5577

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

Merged
merged 2 commits into from
Dec 9, 2018

Conversation

allanrenucci
Copy link
Contributor

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).

@@ -91,12 +96,10 @@ class ElimRepeated extends MiniPhase with InfoTransformer { thisPhase =>
private def seqToArray(tree: Tree, pt: Type)(implicit ctx: Context): Tree = tree match {
case SeqLiteral(elems, elemtpt) =>
JavaSeqLiteral(elems, elemtpt)
case app@Apply(fun, args) if defn.WrapArrayMethods().contains(fun.symbol) => // rewrite a call to `wrapXArray(arr)` to `arr`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why was this optimization dropped?

Copy link
Contributor Author

@allanrenucci allanrenucci Dec 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is no longer needed. When calling into java repeated we used to insert an implicit conversion from Array to Seq that we later reverted. For example:

def test(xs: Array[String]) = Paths.get("Hello", xs: _*)

Before this patch:

// after frontend:
def test(xs: Array[String]) = Paths.get("Hello", wrapRefArray[String](xs):String*)

// after elimRepeated
def test(xs: Array[String]): = Paths.get("Hello", xs)

After this patch:

// after frontend:
def test(xs: Array[String]) = Paths.get("Hello", xs:String*) // no more call to wrapRefArray

// after elimRepeated
def test(xs: Array[String]): = Paths.get("Hello", xs)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for explaining!

@odersky odersky assigned allanrenucci and unassigned odersky Dec 9, 2018
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).
This is not necessary anymore after scala#5403
@allanrenucci
Copy link
Contributor Author

Comments addressed

@allanrenucci allanrenucci merged commit 9a7b67b into scala:master Dec 9, 2018
@allanrenucci allanrenucci deleted the fix-4785 branch December 9, 2018 22:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants