diff options
author | Guillaume Martres <smarter@ubuntu.com> | 2014-12-16 01:32:13 +0100 |
---|---|---|
committer | Guillaume Martres <smarter@ubuntu.com> | 2014-12-16 10:15:05 +0100 |
commit | 5fced3a878bc39827f943d1578d63a3626d0f76f (patch) | |
tree | 722c9c3f507a266652649cdb43a84b312aea2a55 | |
parent | 21fa5dd1a47727c977848163e2610be745951dbc (diff) | |
download | dotty-5fced3a878bc39827f943d1578d63a3626d0f76f.tar.gz dotty-5fced3a878bc39827f943d1578d63a3626d0f76f.tar.bz2 dotty-5fced3a878bc39827f943d1578d63a3626d0f76f.zip |
Avoid spurious warnings about forward references in refinements
The warning was triggered by cases like:
class A
type F = A { type T = Int; def f: T }
Which is treated differently from the following which did not produce a warning:
type F = A { type T = Int } { def f: T }
-rw-r--r-- | src/dotty/tools/dotc/typer/Checking.scala | 4 | ||||
-rw-r--r-- | src/dotty/tools/dotc/typer/Typer.scala | 3 |
2 files changed, 4 insertions, 3 deletions
diff --git a/src/dotty/tools/dotc/typer/Checking.scala b/src/dotty/tools/dotc/typer/Checking.scala index 9e13ec13b..56b5100b1 100644 --- a/src/dotty/tools/dotc/typer/Checking.scala +++ b/src/dotty/tools/dotc/typer/Checking.scala @@ -162,13 +162,13 @@ object Checking { * This depends also on firming up the DOT calculus. For the moment we only issue * deprecated warnings, not errors. */ - def checkRefinementNonCyclic(refinement: Tree, refineCls: ClassSymbol)(implicit ctx: Context): Unit = { + def checkRefinementNonCyclic(refinement: Tree, refineCls: ClassSymbol, seen: mutable.Set[Symbol]) + (implicit ctx: Context): Unit = { def flag(what: String, tree: Tree) = ctx.deprecationWarning(i"$what reference in refinement is deprecated", tree.pos) def forwardRef(tree: Tree) = flag("forward", tree) def selfRef(tree: Tree) = flag("self", tree) val checkTree = new TreeAccumulator[Unit] { - private var seen = Set[Symbol]() def checkRef(tree: Tree, sym: Symbol) = if (sym.maybeOwner == refineCls && !seen(sym)) forwardRef(tree) def apply(x: Unit, tree: Tree) = tree match { diff --git a/src/dotty/tools/dotc/typer/Typer.scala b/src/dotty/tools/dotc/typer/Typer.scala index f6027165b..9ba10d000 100644 --- a/src/dotty/tools/dotc/typer/Typer.scala +++ b/src/dotty/tools/dotc/typer/Typer.scala @@ -759,10 +759,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit val refineClsDef = desugar.refinedTypeToClass(tpt1, tree.refinements) val refineCls = createSymbol(refineClsDef).asClass val TypeDef(_, Template(_, _, _, refinements1)) = typed(refineClsDef) + val seen = mutable.Set[Symbol]() assert(tree.refinements.length == refinements1.length, s"${tree.refinements} != $refinements1") def addRefinement(parent: Type, refinement: Tree): Type = { typr.println(s"adding refinement $refinement") - checkRefinementNonCyclic(refinement, refineCls) + checkRefinementNonCyclic(refinement, refineCls, seen) val rsym = refinement.symbol val rinfo = if (rsym is Accessor) rsym.info.resultType else rsym.info RefinedType(parent, rsym.name, rt => rinfo.substThis(refineCls, RefinedThis(rt))) |