Skip to content

Make 'namePos' return a point position if name is 'nme.ERROR' #4548

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,11 @@ object Trees {
* a calling chain from `viewExists`), in that case the return position is NoPosition.
*/
def namePos =
if (pos.exists)
if (rawMods.is(Synthetic)) Position(pos.point, pos.point)
else Position(pos.point, pos.point + name.stripModuleClassSuffix.lastPart.length, pos.point)
if (pos.exists) {
val point = pos.point
if (rawMods.is(Synthetic) || name.toTermName == nme.ERROR) Position(point)
else Position(point, point + name.stripModuleClassSuffix.lastPart.length, point)
}
else pos
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/interactive/SourceTree.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import scala.io.Codec

import ast.tpd
import core._, core.Decorators.{sourcePos => _, _}
import Contexts._, NameOps._, Symbols._
import Contexts._, NameOps._, Symbols._, StdNames._
import util._, util.Positions._

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