aboutsummaryrefslogtreecommitdiff
path: root/src/dotty/tools/dotc/typer/EtaExpansion.scala
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2014-09-18 17:21:39 +0200
committerDmitry Petrashko <dmitry.petrashko@gmail.com>2014-10-11 08:24:35 +0200
commit117b643d0c20aebac6363057d4043ac2cbb817fe (patch)
tree51342598733a0b431d92352d648ea97db1bb2014 /src/dotty/tools/dotc/typer/EtaExpansion.scala
parent02ab2e85f4570b53e4eab251f6f6a047fd8d168b (diff)
downloaddotty-117b643d0c20aebac6363057d4043ac2cbb817fe.tar.gz
dotty-117b643d0c20aebac6363057d4043ac2cbb817fe.tar.bz2
dotty-117b643d0c20aebac6363057d4043ac2cbb817fe.zip
Fix lifting of application:
Lifting an application `f(arg1).f(args)` requires lifting of the whole prefix `f(arg1)`, because `f` might have a side effect.
Diffstat (limited to 'src/dotty/tools/dotc/typer/EtaExpansion.scala')
-rw-r--r--src/dotty/tools/dotc/typer/EtaExpansion.scala14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/dotty/tools/dotc/typer/EtaExpansion.scala b/src/dotty/tools/dotc/typer/EtaExpansion.scala
index 7c1130b83..394accd03 100644
--- a/src/dotty/tools/dotc/typer/EtaExpansion.scala
+++ b/src/dotty/tools/dotc/typer/EtaExpansion.scala
@@ -84,7 +84,7 @@ object EtaExpansion {
case TypeApply(fn, targs) =>
cpy.TypeApply(tree)(liftApp(defs, fn), targs)
case Select(pre, name) if isPureRef(tree) =>
- cpy.Select(tree)(liftApp(defs, pre), name)
+ cpy.Select(tree)(liftPrefix(defs, pre), name)
case Block(stats, expr) =>
liftApp(defs ++= stats, expr)
case New(tpt) =>
@@ -93,6 +93,18 @@ object EtaExpansion {
lift(defs, tree)
}
+ /** Lift prefix `pre` of an application `pre.f(...)` to
+ *
+ * val x0 = pre
+ * x0.f(...)
+ *
+ * unless `pre` is a `New` or `pre` is idempotent.
+ */
+ def liftPrefix(defs: mutable.ListBuffer[Tree], tree: Tree)(implicit ctx: Context): Tree = tree match {
+ case New(_) => tree
+ case _ => if (isIdempotentExpr(tree)) tree else lift(defs, tree)
+ }
+
/** Eta-expanding a tree means converting a method reference to a function value.
* @param tree The tree to expand
* @param mt The type of the method reference