aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuillaume Martres <smarter@ubuntu.com>2017-02-05 13:28:11 +0100
committerGuillaume Martres <smarter@ubuntu.com>2017-02-05 17:50:09 +0100
commitb0576e977c26a86a400755ab9810b90af73b3b8d (patch)
tree1b0557b13cd7bd398d0ff385283bcb575cbc2fd7
parentac868319ecf75bcffe6000a41379c5c12e92e62e (diff)
downloaddotty-b0576e977c26a86a400755ab9810b90af73b3b8d.tar.gz
dotty-b0576e977c26a86a400755ab9810b90af73b3b8d.tar.bz2
dotty-b0576e977c26a86a400755ab9810b90af73b3b8d.zip
Better positions for infix term operations.
Preserving the position of infix operators is useful for IDEs' type-at-point. We also preserve the position of the untyped lhs of right-associative operators, this is useful both for IDEs and for error messages, before: 4 |val x: List[Int] = "foo" :: List(1) | ^ | found: String($1$) | required: Int | After: scala> val x: List[Int] = "foo" :: List(1) -- [E007] Type Mismatch Error: <console> --------------------------------------- 4 |val x: List[Int] = "foo" :: List(1) | ^^^^^ | found: String($1$) | required: Int | Note: It would be even nicer if we displayed "String" instead of "String($1$)" since $1$ is synthetic, this commit does not address this.
-rw-r--r--compiler/src/dotty/tools/dotc/ast/Desugar.scala6
-rw-r--r--tests/repl/errmsgs.check7
2 files changed, 11 insertions, 2 deletions
diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala
index 3835355e3..eda4a12dc 100644
--- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala
+++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala
@@ -750,12 +750,14 @@ object desugar {
case Tuple(args) => args mapConserve assignToNamedArg
case _ => right :: Nil
}
- Apply(Select(left, op.name), args)
+ val selectPos = Position(left.pos.start, op.pos.end, op.pos.start)
+ Apply(Select(left, op.name).withPos(selectPos), args)
} else {
val x = ctx.freshName().toTermName
+ val selectPos = Position(op.pos.start, right.pos.end, op.pos.start)
new InfixOpBlock(
ValDef(x, TypeTree(), left).withMods(synthetic),
- Apply(Select(right, op.name), Ident(x)))
+ Apply(Select(right, op.name).withPos(selectPos), Ident(x).withPos(left.pos)))
}
}
diff --git a/tests/repl/errmsgs.check b/tests/repl/errmsgs.check
index f0ccdf53f..0dc8e8ae5 100644
--- a/tests/repl/errmsgs.check
+++ b/tests/repl/errmsgs.check
@@ -78,4 +78,11 @@ scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
4 |class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
| ^^^^^^^^
| value `barr` is not a member of Foo(foo) - did you mean `foo.bar`?
+scala> val x: List[Int] = "foo" :: List(1)
+-- [E007] Type Mismatch Error: <console> ---------------------------------------
+4 |val x: List[Int] = "foo" :: List(1)
+ | ^^^^^
+ | found: String($1$)
+ | required: Int
+ |
scala> :quit