Permalink
Browse files

Fix for SI-5610

  • Loading branch information...
lrytz committed May 13, 2012
1 parent b3f7bc9 commit e33901084242b4d7cd76a9279430d0cbc9b9a152
@@ -63,15 +63,18 @@ trait EtaExpansion { self: Analyzer =>
* @return ...
*/
def liftoutPrefix(tree: Tree): Tree = {
- def liftout(tree: Tree): Tree =
+ def liftout(tree: Tree, byName: Boolean): Tree =
if (treeInfo.isExprSafeToInline(tree)) tree
else {
val vname: Name = freshName()
// Problem with ticket #2351 here
defs += atPos(tree.pos) {
- ValDef(Modifiers(SYNTHETIC), vname.toTermName, TypeTree(), tree)
+ val rhs = if (byName) Function(List(), tree) else tree
+ ValDef(Modifiers(SYNTHETIC), vname.toTermName, TypeTree(), rhs)
+ }
+ atPos(tree.pos.focus) {
+ if (byName) Apply(Ident(vname), List()) else Ident(vname)
}
- Ident(vname) setPos tree.pos.focus
}
val tree1 = tree match {
// a partial application using named arguments has the following form:
@@ -85,11 +88,14 @@ trait EtaExpansion { self: Analyzer =>
defs ++= stats
liftoutPrefix(fun)
case Apply(fn, args) =>
- treeCopy.Apply(tree, liftoutPrefix(fn), args mapConserve (liftout)) setType null
+ 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) }
+ treeCopy.Apply(tree, liftoutPrefix(fn), newArgs) setType null
case TypeApply(fn, args) =>
treeCopy.TypeApply(tree, liftoutPrefix(fn), args) setType null
case Select(qual, name) =>
- treeCopy.Select(tree, liftout(qual), name) setSymbol NoSymbol setType null
+ treeCopy.Select(tree, liftout(qual, false), name) setSymbol NoSymbol setType null
case Ident(name) =>
tree
}
@@ -0,0 +1,6 @@
+some string
+some string
+some string
+some string
+List(2, 3)
+List(5, 6)
View
@@ -0,0 +1,30 @@
+object Test {
+ def main(args: Array[String]): Unit = {
+ var test: String = null
+ val fun1: Int => () => Unit = foo(test) _
+ val fun2: Int => () => Unit = foo(test)(_)
+ val fun3: Int => () => Unit = {
+ lazy val eta1: String = test
+ (dummy: Int) => foo(eta1)(dummy)
+ }
+ val fun4: Int => () => Unit = {
+ val eta1: () => String = () => test
+ (dummy: Int) => foo(eta1())(dummy)
+ }
+ test = "some string"
+ fun1(1)()
+ fun2(1)()
+ fun3(1)()
+ fun4(1)()
+
+ val f: (String, Int*) => Unit = m(2, 3)
+ f("", 5, 6)
+ }
+
+ def foo(s: => String)(dummy: Int) = () => println(s)
+
+ def m(a: Int*)(z: String, b: Int*) {
+ println(a.toList)
+ println(b.toList)
+ }
+}

0 comments on commit e339010

Please sign in to comment.