Skip to content

Commit e9f4a07

Browse files
committed
Fix navigation with lazy trees
FIXME: This is too easy to forget, some sort of Traverser should be used instead of using productIterator by hand.
1 parent 291656c commit e9f4a07

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

compiler/src/dotty/tools/dotc/ast/NavigateAST.scala

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package ast
44
import core.Contexts.Context
55
import core.Decorators._
66
import util.Positions._
7-
import Trees.{MemberDef, DefTree}
7+
import Trees.{MemberDef, DefTree, WithLazyField}
88

99
/** Utility functions to go from typed to untyped ASTs */
1010
object NavigateAST {
@@ -75,8 +75,17 @@ object NavigateAST {
7575
path
7676
}
7777
def singlePath(p: Positioned, path: List[Positioned]): List[Positioned] =
78-
if (p.pos contains pos) childPath(p.productIterator, p :: path)
79-
else path
78+
if (p.pos contains pos) {
79+
// FIXME: We shouldn't be manually forcing trees here, we should replace
80+
// our usage of `productIterator` by something in `Positioned` that takes
81+
// care of low-level details like this for us.
82+
p match {
83+
case p: WithLazyField[_] =>
84+
p.forceIfLazy
85+
case _ =>
86+
}
87+
childPath(p.productIterator, p :: path)
88+
} else path
8089
singlePath(from, Nil)
8190
}
82-
}
91+
}

0 commit comments

Comments
 (0)