From 272b165a57d39529a9eb5996bbba64e0c368e43e Mon Sep 17 00:00:00 2001 From: François Garillot Date: Fri, 21 Jun 2013 13:49:37 +0200 Subject: SI-7569 Fix end position in PostfixSelect tree introduced in 5b54681: the end position of Postfix operators should take the operator length into account. review by @som-snytt --- .../scala/tools/nsc/ast/parser/TreeBuilder.scala | 2 +- test/files/run/t7569.check | 12 ++++++++++++ test/files/run/t7569.scala | 19 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) create mode 100644 test/files/run/t7569.check create mode 100644 test/files/run/t7569.scala diff --git a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala index ec4e932aae..0ef71fa1b5 100644 --- a/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala +++ b/src/compiler/scala/tools/nsc/ast/parser/TreeBuilder.scala @@ -245,7 +245,7 @@ abstract class TreeBuilder { /** Tree for `od op`, start is start0 if od.pos is borked. */ def makePostfixSelect(start0: Int, end: Int, od: Tree, op: Name): Tree = { val start = if (od.pos.isDefined) od.pos.startOrPoint else start0 - atPos(r2p(start, end, end)) { new PostfixSelect(od, op.encode) } + atPos(r2p(start, end, end + op.length)) { new PostfixSelect(od, op.encode) } } /** A type tree corresponding to (possibly unary) intersection type */ diff --git a/test/files/run/t7569.check b/test/files/run/t7569.check new file mode 100644 index 0000000000..98513c3ab2 --- /dev/null +++ b/test/files/run/t7569.check @@ -0,0 +1,12 @@ +source-newSource1.scala,line-3,offset=49 A.this.one +source-newSource1.scala,line-3,offset=49 A.this +source-newSource1.scala,line-4,offset=67 A.super.() +source-newSource1.scala,line-4,offset=67 A.super. +source-newSource1.scala,line-4,offset=67 this +source-newSource1.scala,line-3,offset=49 A.this.one +source-newSource1.scala,line-3,offset=49 A.this +RangePosition(newSource1.scala, 55, 57, 65) scala.Int.box(1).toString() +RangePosition(newSource1.scala, 55, 57, 65) scala.Int.box(1).toString +RangePosition(newSource1.scala, 55, 55, 56) scala.Int.box(1) +NoPosition scala.Int.box +NoPosition scala.Int diff --git a/test/files/run/t7569.scala b/test/files/run/t7569.scala new file mode 100644 index 0000000000..b1b1443a18 --- /dev/null +++ b/test/files/run/t7569.scala @@ -0,0 +1,19 @@ +import scala.tools.partest._ +object Test extends CompilerTest { + import global._ + override def extraSettings = super.extraSettings + " -Yrangepos" + override def sources = List( + """|import scala.language.postfixOps + |class A { + | val one = 1 toString + |}""".stripMargin + ) + def check(source: String, unit: CompilationUnit) { + for (ClassDef(_, _, _, Template(_, _, stats)) <- unit.body ; stat <- stats ; t <- stat) { + t match { + case _: Select | _ : Apply | _:This => println("%-15s %s".format(t.pos.toString, t)) + case _ => + } + } + } +} -- cgit v1.2.3