From e1e372cc833e3e9d0d02c1ffa453667f50dbc784 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Mon, 16 Dec 2013 18:33:39 +0100 Subject: Better handling of cyclic reference errors. --- src/dotty/tools/dotc/typer/Namer.scala | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) (limited to 'src/dotty/tools/dotc/typer/Namer.scala') diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index e054aaa3a..3e39c3926 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -47,6 +47,22 @@ trait NamerContextOps { this: Context => def effectiveScope: Scope = if (owner != null && owner.isClass) owner.asClass.decls else scope + + /** The symbol (stored in some typer's symTree) of an enclosing context definition */ + def symOfContextTree(tree: untpd.Tree) = { + def go(ctx: Context): Symbol = { + val typer = ctx.typer + if (typer == null) NoSymbol + else typer.symOfTree get tree match { + case Some(sym) => sym + case None => + var cx = ctx.outer + while (cx.typer eq typer) cx = cx.outer + go(cx) + } + } + go(this) + } } /** This class creates symbols from definitions and imports and gives them @@ -416,7 +432,8 @@ class Namer { typer: Typer => } // println(s"final inherited for $sym: ${inherited.toString}") !!! // println(s"owner = ${sym.owner}, decls = ${sym.owner.info.decls.show}") - def rhsType = adapt(typedAheadExpr(mdef.rhs), WildcardType).tpe.widen + val rhsCtx = ctx.fresh addMode Mode.InferringReturnType + def rhsType = adapt(typedAheadExpr(mdef.rhs)(rhsCtx), WildcardType).tpe.widen def lhsType = fullyDefinedType(rhsType, "right-hand side", mdef.pos) inherited orElse lhsType } -- cgit v1.2.3