File tree Expand file tree Collapse file tree 1 file changed +22
-0
lines changed
compiler/src/dotty/tools/dotc/transform Expand file tree Collapse file tree 1 file changed +22
-0
lines changed Original file line number Diff line number Diff line change @@ -122,6 +122,8 @@ class TreeChecker extends Phase with SymTransformer {
122122 val squahsedPhase = ctx.squashed(prevPhase)
123123 ctx.echo(s " checking ${ctx.compilationUnit} after phase ${squahsedPhase}" )
124124
125+ assertSelectWrapsNew(ctx.compilationUnit.tpdTree)(ctx)
126+
125127 val checkingCtx = ctx
126128 .fresh
127129 .setMode(Mode .ImplicitsEnabled )
@@ -449,6 +451,26 @@ class TreeChecker extends Phase with SymTransformer {
449451 tree
450452 }
451453 }
454+
455+ /**
456+ * Checks that `New` nodes are always wrapped inside `Select` nodes.
457+ */
458+ def assertSelectWrapsNew (tree : tpd.Tree )(implicit ctx : Context ): Unit = {
459+ (new TreeAccumulator [tpd.Tree ] {
460+ override def apply (parent : tpd.Tree , tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = {
461+ tree match {
462+ case tree : tpd.New if ! parent.isInstanceOf [tpd.Select ] =>
463+ assert(assertion = false , i " `New` node must be wrapped in a `Select`: \n parent = ${parent.show}\n child = ${tree.show}" )
464+ case _ : tpd.Annotated =>
465+ // Don't check inside annotations, since they're allowed to contain
466+ // somewhat invalid trees.
467+ case _ =>
468+ foldOver(tree, tree) // replace the parent when folding over the children
469+ }
470+ parent // return the old parent so that my siblings see it
471+ }
472+ })(tpd.EmptyTree , tree)
473+ }
452474}
453475
454476object TreeChecker {
You can’t perform that action at this time.
0 commit comments