File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,10 @@ class TreeChecker extends Phase with SymTransformer {
122
122
val squahsedPhase = ctx.squashed(prevPhase)
123
123
ctx.echo(s " checking ${ctx.compilationUnit} after phase ${squahsedPhase}" )
124
124
125
+ if (ctx.isAfterTyper) {
126
+ assertSelectWrapsNew(ctx.compilationUnit.tpdTree)(ctx)
127
+ }
128
+
125
129
val checkingCtx = ctx
126
130
.fresh
127
131
.setMode(Mode .ImplicitsEnabled )
@@ -449,6 +453,23 @@ class TreeChecker extends Phase with SymTransformer {
449
453
tree
450
454
}
451
455
}
456
+
457
+ /**
458
+ * Checks that `New` nodes are always wrapped inside `Select` nodes.
459
+ */
460
+ def assertSelectWrapsNew (tree : tpd.Tree )(implicit ctx : Context ): Unit = {
461
+ (new TreeAccumulator [tpd.Tree ] {
462
+ override def apply (parent : tpd.Tree , tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = {
463
+ tree match {
464
+ case tree : tpd.New if ! parent.isInstanceOf [tpd.Select ] =>
465
+ assert(assertion = false , i " `New` node must be wrapped in a `Select`: \n parent = ${parent.show}\n child = ${tree.show}" )
466
+ case _ =>
467
+ foldOver(tree, tree) // replace the parent when folding over the children
468
+ }
469
+ parent // return the old parent so that my siblings see it
470
+ }
471
+ })(tpd.EmptyTree , tree)
472
+ }
452
473
}
453
474
454
475
object TreeChecker {
You can’t perform that action at this time.
0 commit comments