Skip to content

Avoid spurious warnings about forward references in refinements #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 16, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/dotty/tools/dotc/typer/Checking.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/dotty/tools/dotc/typer/Typer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
Expand Down