scala / bug

Scala 2 bug reports only. Please, no questions — proper bug reports only.
https://scala-lang.org
232 stars 21 forks source link

TreeInfo.isExprSafeToInline neglects by-name parameter types #7664

Open scabug opened 11 years ago

scabug commented 11 years ago

This is used in a number of places in the compiler. You can see the effect of the bug in eta-expansion:

scala> class C { def foo(a: Any)(b: Any) = a }; def c = new C
defined class C
c: C

scala> reify{def x(c: => C) = c.foo(c) _}.tree
res34: reflect.runtime.universe.Tree =
{
  def x(c: <byname>[$read.C]) = {
    <synthetic> val eta$0$1 = c;
    <synthetic> val eta$1$1 = c;
    ((b) => eta$1$1.foo(eta$0$1)(b))
  };
  ()
}

scala> reify{def byname(f: (=> C) => Any) = (); byname(c => c.foo(c) _)}.tree
res35: reflect.runtime.universe.Tree =
{
  def byname(f: Function1[<byname>[$read.C], Any]) = ();
  byname(((c) => {
    ((b) => c.foo(c)(b))
  }))
}

The two references to the by-name closure parameter c should have been lifted out, as per the first example with a by-name method parameter.

See also my comments in https://github.com/scala/scala/commit/83ae74c.

scabug commented 11 years ago

Imported From: https://issues.scala-lang.org/browse/SI-7664?orig=1 Reporter: @retronym Affected Versions: 2.10.0