aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-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