Skip to content

Commit 5fced3a

Browse files
committed
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 }
1 parent 21fa5dd commit 5fced3a

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/dotty/tools/dotc/typer/Checking.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ object Checking {
162162
* This depends also on firming up the DOT calculus. For the moment we only issue
163163
* deprecated warnings, not errors.
164164
*/
165-
def checkRefinementNonCyclic(refinement: Tree, refineCls: ClassSymbol)(implicit ctx: Context): Unit = {
165+
def checkRefinementNonCyclic(refinement: Tree, refineCls: ClassSymbol, seen: mutable.Set[Symbol])
166+
(implicit ctx: Context): Unit = {
166167
def flag(what: String, tree: Tree) =
167168
ctx.deprecationWarning(i"$what reference in refinement is deprecated", tree.pos)
168169
def forwardRef(tree: Tree) = flag("forward", tree)
169170
def selfRef(tree: Tree) = flag("self", tree)
170171
val checkTree = new TreeAccumulator[Unit] {
171-
private var seen = Set[Symbol]()
172172
def checkRef(tree: Tree, sym: Symbol) =
173173
if (sym.maybeOwner == refineCls && !seen(sym)) forwardRef(tree)
174174
def apply(x: Unit, tree: Tree) = tree match {

src/dotty/tools/dotc/typer/Typer.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -759,10 +759,11 @@ class Typer extends Namer with TypeAssigner with Applications with Implicits wit
759759
val refineClsDef = desugar.refinedTypeToClass(tpt1, tree.refinements)
760760
val refineCls = createSymbol(refineClsDef).asClass
761761
val TypeDef(_, Template(_, _, _, refinements1)) = typed(refineClsDef)
762+
val seen = mutable.Set[Symbol]()
762763
assert(tree.refinements.length == refinements1.length, s"${tree.refinements} != $refinements1")
763764
def addRefinement(parent: Type, refinement: Tree): Type = {
764765
typr.println(s"adding refinement $refinement")
765-
checkRefinementNonCyclic(refinement, refineCls)
766+
checkRefinementNonCyclic(refinement, refineCls, seen)
766767
val rsym = refinement.symbol
767768
val rinfo = if (rsym is Accessor) rsym.info.resultType else rsym.info
768769
RefinedType(parent, rsym.name, rt => rinfo.substThis(refineCls, RefinedThis(rt)))

0 commit comments

Comments
 (0)