Skip to content

Commit dd609e2

Browse files
authored
Merge pull request #4548 from dotty-staging/pos-error
Make 'namePos' return a point position if name is 'nme.ERROR'
2 parents 1a7144a + d198b18 commit dd609e2

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -337,9 +337,11 @@ object Trees {
337337
* a calling chain from `viewExists`), in that case the return position is NoPosition.
338338
*/
339339
def namePos =
340-
if (pos.exists)
341-
if (rawMods.is(Synthetic)) Position(pos.point, pos.point)
342-
else Position(pos.point, pos.point + name.stripModuleClassSuffix.lastPart.length, pos.point)
340+
if (pos.exists) {
341+
val point = pos.point
342+
if (rawMods.is(Synthetic) || name.toTermName == nme.ERROR) Position(point)
343+
else Position(point, point + name.stripModuleClassSuffix.lastPart.length, point)
344+
}
343345
else pos
344346
}
345347

compiler/src/dotty/tools/dotc/interactive/SourceTree.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import scala.io.Codec
66

77
import ast.tpd
88
import core._, core.Decorators.{sourcePos => _, _}
9-
import Contexts._, NameOps._, Symbols._
9+
import Contexts._, NameOps._, Symbols._, StdNames._
1010
import util._, util.Positions._
1111

1212
/** A typechecked named `tree` coming from `source` */
@@ -18,7 +18,7 @@ case class SourceTree(tree: tpd.NameTree, source: SourceFile) {
1818
def namePos(implicit ctx: Context): SourcePosition = {
1919
// FIXME: Merge with NameTree#namePos ?
2020
val treePos = tree.pos
21-
if (treePos.isZeroExtent)
21+
if (treePos.isZeroExtent || tree.name.toTermName == nme.ERROR)
2222
NoSourcePosition
2323
else {
2424
val nameLength = tree.name.stripModuleClassSuffix.show.toString.length

0 commit comments

Comments
 (0)