Skip to content

Commit 8d560fa

Browse files
committed
Getters now also makes getters for lazy vals.
1 parent c376e0c commit 8d560fa

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/dotty/tools/dotc/transform/Getters.scala

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,21 @@ import Decorators._
1616
/** Performs the following rewritings for fields of a class:
1717
*
1818
* <mods> val x: T = e
19-
* --> <mods> <stable> def x: T = e
19+
* --> <mods> <stable> <accessor> def x: T = e
2020
* <mods> var x: T = e
21-
* --> <mods> def x: T = e
21+
* --> <mods> <accessor> def x: T = e
2222
*
2323
* <mods> val x: T
24-
* --> <mods> <stable> def x: T
24+
* --> <mods> <stable> <accessor> def x: T
25+
*
26+
* <mods> lazy val x: T = e
27+
* --> <mods> <accessor> lazy def x: T =e
2528
*
2629
* <mods> var x: T
27-
* --> <mods> def x: T
30+
* --> <mods> <accessor> def x: T
31+
*
32+
* <mods> non-static <module> val x$ = e
33+
* --> <mods> <module> <accessor> def x$ = e
2834
*
2935
* Omitted from the rewritings are
3036
*
@@ -47,18 +53,18 @@ class Getters extends MiniPhaseTransform with SymTransformer { thisTransform =>
4753
override def transformSym(d: SymDenotation)(implicit ctx: Context): SymDenotation = {
4854
def noGetterNeeded =
4955
d.is(NoGetterNeeded) ||
50-
d.initial.asInstanceOf[SymDenotation].is(PrivateLocal) && !d.owner.is(Trait) ||
56+
d.initial.asInstanceOf[SymDenotation].is(PrivateLocal) && !d.owner.is(Trait) && !d.is(Flags.Lazy) ||
5157
d.is(Module) && d.isStatic ||
5258
d.isSelfSym
53-
if (d.isTerm && d.owner.isClass && d.info.isValueType && !noGetterNeeded) {
59+
if (d.isTerm && (d.is(Lazy) || d.owner.isClass) && d.info.isValueType && !noGetterNeeded) {
5460
val maybeStable = if (d.isStable) Stable else EmptyFlags
5561
d.copySymDenotation(
5662
initFlags = d.flags | maybeStable | AccessorCreationFlags,
5763
info = ExprType(d.info))
5864
}
5965
else d
6066
}
61-
private val NoGetterNeeded = Method | Param | JavaDefined | JavaStatic | Lazy
67+
private val NoGetterNeeded = Method | Param | JavaDefined | JavaStatic
6268

6369
override def transformValDef(tree: ValDef)(implicit ctx: Context, info: TransformerInfo): Tree =
6470
if (tree.symbol is Method) DefDef(tree.symbol.asTerm, tree.rhs) else tree

0 commit comments

Comments
 (0)