Subtle change in outer capture under -Ydelambdafy:method #9408
Closed
Description
// test.scala
class C {
def test {
println({() => class D; classOf[D].getDeclaredFields.mkString(",")}.apply())
}
}
object Test {
def main(args: Array[String]): Unit = {
new C().test
}
}
% scalac-hash v2.11.7 test.scala && scala-hash v2.11.7 Test
public final C$$anonfun$test$1 C$$anonfun$test$1$D$1.$outer
% scalac-hash v2.11.7 -Ydelambdafy:method test.scala && scala-hash v2.11.7 -Ydelambdafy:method Test
public final C C$D$1.$outer
This difference is observable via a change in memory retention, or a change in the serializability of D (as seen in the wild in Shapeless: milessabin/shapeless@ac12155)
I'm not really sure why we need an outer pointer at all for a local class such as D.