Skip to content

Commit de97de5

Browse files
committed
Add a postcondition to constructors.
1 parent 10424c6 commit de97de5

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,17 @@ class Constructors extends MiniPhaseTransform with SymTransformer { thisTransfor
3232
override def phaseName: String = "constructors"
3333
override def runsAfter: Set[Class[_ <: Phase]] = Set(classOf[Erasure])
3434

35+
36+
/** All initializers should be moved into constructor
37+
*/
38+
override def checkPostCondition(tree: tpd.Tree)(implicit ctx: Context): Unit = {
39+
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 _ =>
43+
}
44+
}
45+
3546
/** Symbols that are owned by either <local dummy> or a class field move into the
3647
* primary constructor.
3748
*/

0 commit comments

Comments
 (0)