Skip to content

Commit

Permalink
Fix nestingLevel so that it works for NoDenotation
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed May 9, 2020
1 parent 202d862 commit e97b278
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1450,9 +1450,10 @@ object SymDenotations {
else if is(Contravariant) then Contravariant
else EmptyFlags

/** The length of the owner chain of this symbol. 0 for _root_, undefined for NoSymbol */
/** The length of the owner chain of this symbol. 1 for _root_, 0 for NoSymbol */
def nestingLevel(using Context): Int =
@tailrec def recur(d: SymDenotation, n: Int): Int = d match
case NoDenotation => n
case d: ClassDenotation => d.nestingLevel + n // profit from the cache in ClassDenotation
case _ => recur(d.owner, n + 1)
recur(this, 0)
Expand Down Expand Up @@ -2162,8 +2163,7 @@ object SymDenotations {
private var myNestingLevel = -1

override def nestingLevel(using Context) =
if myNestingLevel == -1 then
myNestingLevel = if maybeOwner.exists then maybeOwner.nestingLevel + 1 else 0
if myNestingLevel == -1 then myNestingLevel = owner.nestingLevel + 1
myNestingLevel
}

Expand Down

0 comments on commit e97b278

Please sign in to comment.