Skip to content

Commit 1fccf71

Browse files
authored
Merge pull request scala#9761 from lrytz/infix-rangepos
Fix range position end for infix calls
2 parents ec0b07f + 3ae1f5f commit 1fccf71

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

src/compiler/scala/tools/nsc/ast/parser/Parsers.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ self =>
924924
def finishBinaryOp(isExpr: Boolean, opinfo: OpInfo, rhs: Tree): Tree = {
925925
import opinfo._
926926
val operatorPos: Position = Position.range(rhs.pos.source, offset, offset, offset + operator.length)
927-
val pos = lhs.pos union rhs.pos union operatorPos withPoint offset
927+
val pos = lhs.pos.union(rhs.pos).union(operatorPos).withEnd(in.lastOffset).withPoint(offset)
928928

929929
atPos(pos)(makeBinop(isExpr, lhs, operator, rhs, operatorPos, opinfo.targs))
930930
}

test/files/run/infix-rangepos.scala

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import scala.tools.partest._
2+
3+
object Test extends CompilerTest {
4+
import global._
5+
override def extraSettings = super.extraSettings + " -Yrangepos"
6+
override def sources = List(
7+
"class C1 { def t = List(1).map ( x => x ) }",
8+
"class C2 { def t = List(1).map { x => x } }",
9+
"class C3 { def t = List(1).map ({x => x}) }",
10+
"class C4 { def t = List(1) map ( x => x ) }",
11+
"class C5 { def t = List(1) map { x => x } }",
12+
"class C6 { def t = List(1) map ({x => x}) }")
13+
14+
def check(source: String, unit: CompilationUnit): Unit = unit.body foreach {
15+
case dd: DefDef if dd.name.startsWith("t") =>
16+
val pos = dd.rhs.pos
17+
assert(pos.start == 19, pos.start)
18+
assert(pos.end == 41, pos.end)
19+
case _ =>
20+
}
21+
}

0 commit comments

Comments
 (0)