diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2012-06-23 19:04:50 +0200 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2012-06-23 19:22:22 +0200 |
commit | 4736897ad2a6425c64cadfe80d5e6d7751ee0fec (patch) | |
tree | 530a4a95010fe8f8d8daf509cb552fa61ce739d7 | |
parent | ff016002738580a7de11977c91e0061dbcf270ad (diff) | |
download | scala-4736897ad2a6425c64cadfe80d5e6d7751ee0fec.tar.gz scala-4736897ad2a6425c64cadfe80d5e6d7751ee0fec.tar.bz2 scala-4736897ad2a6425c64cadfe80d5e6d7751ee0fec.zip |
SI-5966 Fix eta expansion for repeated parameters with zero arguments.
Reworks part of e33901 / SI-5610, which was inserting an <empty> tree
as an argument in this case, which turns into a null in icode.
-rw-r--r-- | src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala | 8 | ||||
-rw-r--r-- | test/files/run/t5966.check | 3 | ||||
-rw-r--r-- | test/files/run/t5966.scala | 9 |
3 files changed, 17 insertions, 3 deletions
diff --git a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala index e1fb683aa9..177d1ddf19 100644 --- a/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala +++ b/src/compiler/scala/tools/nsc/typechecker/EtaExpansion.scala @@ -88,9 +88,11 @@ trait EtaExpansion { self: Analyzer => defs ++= stats liftoutPrefix(fun) case Apply(fn, args) => - val byName = fn.tpe.params.map(p => definitions.isByNameParamType(p.tpe)) - // zipAll: with repeated params, there might be more args than params - val newArgs = args.zipAll(byName, EmptyTree, false) map { case (arg, byN) => liftout(arg, byN) } + val byName: Int => Option[Boolean] = fn.tpe.params.map(p => definitions.isByNameParamType(p.tpe)).lift + val newArgs = mapWithIndex(args) { (arg, i) => + // with repeated params, there might be more or fewer args than params + liftout(arg, byName(i).getOrElse(false)) + } treeCopy.Apply(tree, liftoutPrefix(fn), newArgs) setType null case TypeApply(fn, args) => treeCopy.TypeApply(tree, liftoutPrefix(fn), args) setType null diff --git a/test/files/run/t5966.check b/test/files/run/t5966.check new file mode 100644 index 0000000000..bfe8358a77 --- /dev/null +++ b/test/files/run/t5966.check @@ -0,0 +1,3 @@ +(o()_)("") = List() +(o("a1")_)("") = WrappedArray(a1) +(o("a1", "a2")_)("") = WrappedArray(a1, a2) diff --git a/test/files/run/t5966.scala b/test/files/run/t5966.scala new file mode 100644 index 0000000000..bbe1a6e874 --- /dev/null +++ b/test/files/run/t5966.scala @@ -0,0 +1,9 @@ +object o { def apply(i: AnyRef*)(j: String) = i } + +object Test { + def main(args: Array[String]) { + println("(o()_)(\"\") = " + (o()_)("")) + println("(o(\"a1\")_)(\"\") = " + (o("a1")_)("")) + println("(o(\"a1\", \"a2\")_)(\"\") = " + (o("a1", "a2")_)("")) + } +} |