summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Rudolph <johannes_rudolph@gmx.de>2012-05-08 21:16:33 +0200
committerJohannes Rudolph <johannes_rudolph@gmx.de>2012-05-08 21:46:56 +0200
commit00a648bc909f794d91570fb962fc7d7fcd055bc5 (patch)
tree19e0b891ab425e7f569a03a9158d3b610b70cd38
parentda04d691c455aa3f3391bdbd9bac7fb59f29cedf (diff)
downloadscala-00a648bc909f794d91570fb962fc7d7fcd055bc5.tar.gz
scala-00a648bc909f794d91570fb962fc7d7fcd055bc5.tar.bz2
scala-00a648bc909f794d91570fb962fc7d7fcd055bc5.zip
fix SI-1247: don't create a thunk for a by-name argument if the argument expression is a Function0 application
-rw-r--r--src/compiler/scala/tools/nsc/transform/UnCurry.scala10
-rw-r--r--test/files/run/t1247.check1
-rw-r--r--test/files/run/t1247.scala11
3 files changed, 21 insertions, 1 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/UnCurry.scala b/src/compiler/scala/tools/nsc/transform/UnCurry.scala
index ef98935f9c..7f220992a3 100644
--- a/src/compiler/scala/tools/nsc/transform/UnCurry.scala
+++ b/src/compiler/scala/tools/nsc/transform/UnCurry.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)
+ }
}
}
}
diff --git a/test/files/run/t1247.check b/test/files/run/t1247.check
new file mode 100644
index 0000000000..ce123032fd
--- /dev/null
+++ b/test/files/run/t1247.check
@@ -0,0 +1 @@
+Is same closure class: true is same closure: true
diff --git a/test/files/run/t1247.scala b/test/files/run/t1247.scala
new file mode 100644
index 0000000000..c709b73bc8
--- /dev/null
+++ b/test/files/run/t1247.scala
@@ -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())
+}