Skip to content

Commit 87442de

Browse files
committed
Merge postConditions of memoize and constructors
If memoize and constructors are run in different groups, memoize's previous postcondition "all concerete methods are implemented" is wrong, because constructors are not implemengted yet. Solved by moving the postcondition to phase Constructors.
1 parent 878b55a commit 87442de

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,19 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
3030
import tpd._
3131

3232
override def phaseName: String = "constructors"
33-
override def runsAfter: Set[Class[_ <: Phase]] = Set(classOf[Erasure])
33+
override def runsAfter: Set[Class[_ <: Phase]] = Set(classOf[Memoize])
3434

3535

36-
/** All initializers should be moved into constructor
37-
*/
36+
/** All initializers for non-lazy fields should be moved into constructor.
37+
* All non-abstract methods should be implemented (this is assured for constructors
38+
* in this phase and for other methods in memoize).
39+
*/
3840
override def checkPostCondition(tree: tpd.Tree)(implicit ctx: Context): Unit = {
3941
tree match {
40-
case t: ValDef if ((t.rhs ne EmptyTree) && !(t.symbol is Flags.Lazy) && t.symbol.owner.isClass) =>
41-
assert(false, i"$t initializers should be moved to constructors")
42+
case tree: ValDef if tree.symbol.exists && tree.symbol.owner.isClass && !tree.symbol.is(Lazy) =>
43+
assert(tree.rhs.isEmpty, i"$tree: initializer should be moved to constructors")
44+
case tree: DefDef if !tree.symbol.is(LazyOrDeferred) =>
45+
assert(!tree.rhs.isEmpty, i"unimplemented: $tree")
4246
case _ =>
4347
}
4448
}

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,6 @@ import Decorators._
4242
*/
4343
override def runsAfter: Set[Class[_ <: Phase]] = Set(classOf[Mixin])
4444

45-
override def checkPostCondition(tree: Tree)(implicit ctx: Context): Unit = tree match {
46-
case tree: DefDef if !tree.symbol.is(Lazy | Deferred) =>
47-
assert(!tree.rhs.isEmpty, i"unimplemented: $tree")
48-
case _ =>
49-
}
50-
5145
override def transformDefDef(tree: DefDef)(implicit ctx: Context, info: TransformerInfo): Tree = {
5246
val sym = tree.symbol
5347

0 commit comments

Comments
 (0)