diff options
Diffstat (limited to 'src/dotty/tools/dotc/transform/TreeChecker.scala')
-rw-r--r-- | src/dotty/tools/dotc/transform/TreeChecker.scala | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/dotty/tools/dotc/transform/TreeChecker.scala b/src/dotty/tools/dotc/transform/TreeChecker.scala index f39dd505a..42e4f95ba 100644 --- a/src/dotty/tools/dotc/transform/TreeChecker.scala +++ b/src/dotty/tools/dotc/transform/TreeChecker.scala @@ -8,6 +8,7 @@ import core.SymDenotations._ import core.Contexts._ import core.Symbols._ import core.Types._ +import core.Flags.Method import core.Constants._ import core.StdNames._ import core.Decorators._ @@ -72,6 +73,24 @@ class TreeChecker { assert(tree.isTerm || ctx.phase.prev.id <= ctx.typerPhase.id, tree.show + " at " + ctx.phase) super.typedSelect(tree, pt) } + + /** Check that all defined symbols have legal owners. + * An owner is legal if it is either the same as the context's owner + * or there's an owner chain of valdefs starting at the context's owner and + * reaching up to the symbol's owner. The reason for this relaxed matching + * is that we should be able to pull out an expression as an initializer + * of a helper value without having to do a change owner traversal of the expression. + */ + override def index(trees: List[untpd.Tree])(implicit ctx: Context): Context = { + def ownerMatches(symOwner: Symbol, ctxOwner: Symbol): Boolean = + symOwner == ctxOwner || + ctxOwner.isTerm && !(ctxOwner is Method | Lazy | Mutable) && + ownerMatches(symOwner, ctxOwner.owner) + for (tree <- trees if tree.isDef) + assert(ownerMatches(tree.symbol.owner, ctx.owner), + i"bad owner; $tree has owner ${tree.symbol.owner}, expected was ${ctx.owner}") + super.index(trees) + } } } |