diff options
author | Nicolas Stucki <nicolas.stucki@gmail.com> | 2017-03-01 10:11:49 +0100 |
---|---|---|
committer | Nicolas Stucki <nicolas.stucki@gmail.com> | 2017-03-01 13:03:44 +0100 |
commit | be5720c18ca6768c7e72d4258677952848db2bb4 (patch) | |
tree | a781b4f8b2772de09db54352d2d50602a1a0a4a6 /compiler/src/dotty/tools/dotc/transform | |
parent | 1a490393d766039332bfccb8b85f264f22c9e9cc (diff) | |
download | dotty-be5720c18ca6768c7e72d4258677952848db2bb4.tar.gz dotty-be5720c18ca6768c7e72d4258677952848db2bb4.tar.bz2 dotty-be5720c18ca6768c7e72d4258677952848db2bb4.zip |
Add @tailrec to avoid regressions.
Diffstat (limited to 'compiler/src/dotty/tools/dotc/transform')
-rw-r--r-- | compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala | 4 | ||||
-rw-r--r-- | compiler/src/dotty/tools/dotc/transform/SymUtils.scala | 6 |
2 files changed, 7 insertions, 3 deletions
diff --git a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala index d75c32fcc..44308012e 100644 --- a/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala +++ b/compiler/src/dotty/tools/dotc/transform/ExplicitOuter.scala @@ -16,7 +16,9 @@ import SymUtils._ import dotty.tools.dotc.ast.tpd import dotty.tools.dotc.core.Phases.Phase import util.Property + import collection.mutable +import scala.annotation.tailrec /** This phase adds outer accessors to classes and traits that need them. * Compared to Scala 2.x, it tries to minimize the set of classes @@ -367,7 +369,7 @@ object ExplicitOuter { def path(start: Tree = This(ctx.owner.lexicallyEnclosingClass.asClass), toCls: Symbol = NoSymbol, count: Int = -1): Tree = try { - def loop(tree: Tree, count: Int): Tree = { + @tailrec def loop(tree: Tree, count: Int): Tree = { val treeCls = tree.tpe.widen.classSymbol val outerAccessorCtx = ctx.withPhaseNoLater(ctx.lambdaLiftPhase) // lambdalift mangles local class names, which means we cannot reliably find outer acessors anymore ctx.log(i"outer to $toCls of $tree: ${tree.tpe}, looking for ${outerAccName(treeCls.asClass)(outerAccessorCtx)} in $treeCls") diff --git a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala index 05305575e..105f54d3a 100644 --- a/compiler/src/dotty/tools/dotc/transform/SymUtils.scala +++ b/compiler/src/dotty/tools/dotc/transform/SymUtils.scala @@ -12,7 +12,9 @@ import StdNames._ import NameOps._ import Flags._ import Annotations._ + import language.implicitConversions +import scala.annotation.tailrec object SymUtils { implicit def decorateSymbol(sym: Symbol): SymUtils = new SymUtils(sym) @@ -59,14 +61,14 @@ class SymUtils(val self: Symbol) extends AnyVal { } /** The closest enclosing method or class of this symbol */ - final def enclosingMethodOrClass(implicit ctx: Context): Symbol = + @tailrec final def enclosingMethodOrClass(implicit ctx: Context): Symbol = if (self.is(Method, butNot = Label) || self.isClass) self else if (self.exists) self.owner.enclosingMethodOrClass else NoSymbol /** Apply symbol/symbol substitution to this symbol */ def subst(from: List[Symbol], to: List[Symbol]): Symbol = { - def loop(from: List[Symbol], to: List[Symbol]): Symbol = + @tailrec def loop(from: List[Symbol], to: List[Symbol]): Symbol = if (from.isEmpty) self else if (self eq from.head) to.head else loop(from.tail, to.tail) |