From e5fc2be4db3793269aae63b83d0c28ab6edb760e Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Sun, 20 May 2018 00:18:00 +0300 Subject: [PATCH 1/3] Make 'namePos' return a point position if name is 'nme.ERROR' 'namePos' used to return nonsensical position when the tree was malformed (e.g. "case class"). --- compiler/src/dotty/tools/dotc/ast/Trees.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index 32235e35e904..c665f8b4e7ec 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -338,7 +338,7 @@ object Trees { */ def namePos = if (pos.exists) - if (rawMods.is(Synthetic)) Position(pos.point, pos.point) + if (rawMods.is(Synthetic) || name.toTermName == nme.ERROR) Position(pos.point, pos.point) else Position(pos.point, pos.point + name.stripModuleClassSuffix.lastPart.length, pos.point) else pos } From 7faeced451506a3dfd97508ccd9ab5234456d15e Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Tue, 22 May 2018 11:51:27 +0200 Subject: [PATCH 2/3] Compute 'pos.point' only once --- compiler/src/dotty/tools/dotc/ast/Trees.scala | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/Trees.scala b/compiler/src/dotty/tools/dotc/ast/Trees.scala index c665f8b4e7ec..1a0d52497085 100644 --- a/compiler/src/dotty/tools/dotc/ast/Trees.scala +++ b/compiler/src/dotty/tools/dotc/ast/Trees.scala @@ -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) || name.toTermName == nme.ERROR) 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 } From d198b18e5c05e6690b9fa3209467a78115741d11 Mon Sep 17 00:00:00 2001 From: Allan Renucci Date: Tue, 22 May 2018 18:10:37 +0200 Subject: [PATCH 3/3] Fix namePos in SourceTree as well --- compiler/src/dotty/tools/dotc/interactive/SourceTree.scala | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/interactive/SourceTree.scala b/compiler/src/dotty/tools/dotc/interactive/SourceTree.scala index 6598e9c8d198..2ef05c7393ed 100644 --- a/compiler/src/dotty/tools/dotc/interactive/SourceTree.scala +++ b/compiler/src/dotty/tools/dotc/interactive/SourceTree.scala @@ -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` */ @@ -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