aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2015-03-13 17:19:07 +0100
committerMartin Odersky <odersky@gmail.com>2015-03-13 17:19:07 +0100
commit3e849296a8563a561f53c92b48bd720897694b63 (patch)
tree30f98d03708e48db9f1bc4c42bcdfc48a14bf69c
parent0ee93122b9e367c08ed1d81c9cfc5919fc3a32af (diff)
downloaddotty-3e849296a8563a561f53c92b48bd720897694b63.tar.gz
dotty-3e849296a8563a561f53c92b48bd720897694b63.tar.bz2
dotty-3e849296a8563a561f53c92b48bd720897694b63.zip
Fix #400
In a call-by-name arg, replace () => f.apply() with f only if f is pure.
-rw-r--r--src/dotty/tools/dotc/transform/ElimByName.scala3
-rw-r--r--tests/pos/i0400.scala13
2 files changed, 15 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/transform/ElimByName.scala b/src/dotty/tools/dotc/transform/ElimByName.scala
index ff774b462..5bd9c045a 100644
--- a/src/dotty/tools/dotc/transform/ElimByName.scala
+++ b/src/dotty/tools/dotc/transform/ElimByName.scala
@@ -73,7 +73,8 @@ class ElimByName extends MiniPhaseTransform with InfoTransformer { thisTransform
case formalExpr: ExprType =>
val argType = arg.tpe.widen
val argFun = arg match {
- case Apply(Select(qual, nme.apply), Nil) if qual.tpe derivesFrom defn.FunctionClass(0) =>
+ case Apply(Select(qual, nme.apply), Nil)
+ if qual.tpe.derivesFrom(defn.FunctionClass(0)) && isPureExpr(qual) =>
qual
case _ =>
val meth = ctx.newSymbol(
diff --git a/tests/pos/i0400.scala b/tests/pos/i0400.scala
new file mode 100644
index 000000000..701dc88fd
--- /dev/null
+++ b/tests/pos/i0400.scala
@@ -0,0 +1,13 @@
+object Test {
+ def foo: Unit = {
+ def a = () => ""
+ bar({???; a}.apply())
+ }
+ def bar(a: => Any): Unit = {
+ baz(a)
+ }
+ def baz(a: => Any): Unit = ()
+ def main(args: Array[String]): Unit = {
+ foo
+ }
+}