Skip to content

Commit e97b278

Browse files
committed
Fix nestingLevel so that it works for NoDenotation
1 parent 202d862 commit e97b278

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

compiler/src/dotty/tools/dotc/core/SymDenotations.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,9 +1450,10 @@ object SymDenotations {
14501450
else if is(Contravariant) then Contravariant
14511451
else EmptyFlags
14521452

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

21642165
override def nestingLevel(using Context) =
2165-
if myNestingLevel == -1 then
2166-
myNestingLevel = if maybeOwner.exists then maybeOwner.nestingLevel + 1 else 0
2166+
if myNestingLevel == -1 then myNestingLevel = owner.nestingLevel + 1
21672167
myNestingLevel
21682168
}
21692169

0 commit comments

Comments
 (0)