Open
Description
Simple example:
object ObjectWithLazyVal {
lazy val lazyFoo = {
println("foo")
"foo"
}
}
With Scala 2.11.8
there are two statements, with Scala 2.12.1
- zero.
This is caused by internal changes in Scala 2.12.
In Scoverage plugin there is (in tag v1.3.0, in master
it's slightly simplified):
/**
* We can ignore lazy val defs as they are implemented by a generated defdef
*/
case v: ValDef if v.symbol.isLazy =>
val w = v
tree
Scala 2.12
does not generate mentioned defs.
ModuleDef
tree (viewed in debugger) for the above example object looks like this with Scala 2.11.8
:
object ObjectWithLazyVal extends scala.AnyRef {
def <init>(): ObjectWithLazyVal.type = {
ObjectWithLazyVal.super.<init>();
()
};
lazy private[this] var lazyFoo: String = _;
<stable> <accessor> lazy def lazyFoo: String = {
ObjectWithLazyVal.this.lazyFoo = {
scala.this.Predef.println("foo");
"foo"
};
ObjectWithLazyVal.this.lazyFoo
}
}
and with Scala 2.12.1
:
object ObjectWithLazyVal extends scala.AnyRef {
def <init>(): ObjectWithLazyVal.type = {
ObjectWithLazyVal.super.<init>();
()
};
<stable> <accessor> lazy val lazyFoo: String = {
scala.Predef.println("foo");
"foo"
}
}
Compiled classes look identical.