Permalink
Browse files

fix SI-1247: don't create a thunk for a by-name argument if the argum…

…ent expression is a Function0 application
  • Loading branch information...
jrudolph committed May 8, 2012
1 parent da04d69 commit 00a648bc909f794d91570fb962fc7d7fcd055bc5
Showing with 21 additions and 1 deletion.
  1. +9 −1 src/compiler/scala/tools/nsc/transform/UnCurry.scala
  2. +1 −0 test/files/run/t1247.check
  3. +11 −0 test/files/run/t1247.scala
@@ -473,7 +473,15 @@ abstract class UnCurry extends InfoTransform
arg.pos.source.path + ":" + arg.pos.line, fun.fullName,
if (fun.isPrivate) "private" else "")
)
newFunction0(arg)
arg match {
// don't add a thunk for by-name argument if argument already is an application of
// a Function0. We can then remove the application and use the existing Function0.
case Apply(Select(recv, nme.apply), Nil) if recv.tpe.typeSymbol isSubClass FunctionClass(0) =>
recv
case _ =>
newFunction0(arg)
}
}
}
}
@@ -0,0 +1 @@
Is same closure class: true is same closure: true
View
@@ -0,0 +1,11 @@
object Test extends App {
val f = () => 5
def test(g: => Int) {
val gFunc = g _
val isSameClosureClass = gFunc.getClass == f.getClass
val isSame = gFunc eq f
println("Is same closure class: "+isSameClosureClass+" is same closure: "+isSame)
}
test(f())
}

0 comments on commit 00a648b

Please sign in to comment.