Skip to content

Commit ab124cb

Browse files
authored
Merge pull request #2268 from dotty-staging/topic/add-line-col
Render line and col in error message for clickability
2 parents f20ca3d + da3d8b2 commit ab124cb

File tree

4 files changed

+17
-17
lines changed

4 files changed

+17
-17
lines changed

compiler/src/dotty/tools/dotc/reporting/MessageRendering.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ trait MessageRendering {
113113
*/
114114
def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(implicit ctx: Context): String =
115115
if (pos.exists) Blue({
116-
val file = pos.source.file.toString
116+
val file = s"${pos.source.file.toString}:${pos.line + 1}:${pos.column}"
117117
val errId =
118118
if (message.errorId ne ErrorMessageID.NoExplanationID) {
119119
val errorNumber = message.errorId.errorNumber()

tests/repl/errmsgs.check

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
scala> class Inv[T](x: T)
22
defined class Inv
33
scala> val x: List[String] = List(1)
4-
-- [E007] Type Mismatch Error: <console> ---------------------------------------
4+
-- [E007] Type Mismatch Error: <console>:4:27 ----------------------------------
55
4 |val x: List[String] = List(1)
66
| ^
77
| found: Int(1)
88
| required: String
99
|
1010
scala> val y: List[List[String]] = List(List(1))
11-
-- [E007] Type Mismatch Error: <console> ---------------------------------------
11+
-- [E007] Type Mismatch Error: <console>:4:38 ----------------------------------
1212
4 |val y: List[List[String]] = List(List(1))
1313
| ^
1414
| found: Int(1)
1515
| required: String
1616
|
1717
scala> val z: (List[String], List[Int]) = (List(1), List("a"))
18-
-- [E007] Type Mismatch Error: <console> ---------------------------------------
18+
-- [E007] Type Mismatch Error: <console>:4:41 ----------------------------------
1919
4 |val z: (List[String], List[Int]) = (List(1), List("a"))
2020
| ^
2121
| found: Int(1)
2222
| required: String
2323
|
24-
-- [E007] Type Mismatch Error: <console> ---------------------------------------
24+
-- [E007] Type Mismatch Error: <console>:4:50 ----------------------------------
2525
4 |val z: (List[String], List[Int]) = (List(1), List("a"))
2626
| ^^^
2727
| found: String("a")
2828
| required: Int
2929
|
3030
scala> val a: Inv[String] = new Inv(new Inv(1))
31-
-- [E007] Type Mismatch Error: <console> ---------------------------------------
31+
-- [E007] Type Mismatch Error: <console>:5:33 ----------------------------------
3232
5 |val a: Inv[String] = new Inv(new Inv(1))
3333
| ^^^^^
3434
| found: Inv[T]
3535
| required: String
3636
|
3737
| where: T is a type variable with constraint >: Int(1)
3838
scala> val b: Inv[String] = new Inv(1)
39-
-- [E007] Type Mismatch Error: <console> ---------------------------------------
39+
-- [E007] Type Mismatch Error: <console>:5:29 ----------------------------------
4040
5 |val b: Inv[String] = new Inv(1)
4141
| ^
4242
| found: Int(1)
@@ -57,15 +57,15 @@ scala> abstract class C {
5757
}
5858
}
5959
}
60-
-- [E007] Type Mismatch Error: <console> ---------------------------------------
60+
-- [E007] Type Mismatch Error: <console>:9:17 ----------------------------------
6161
9 | var y: T = x
6262
| ^
6363
|found: C.this.T(C.this.x)
6464
|required: T'
6565
|
6666
|where: T is a type in class C
6767
| T' is a type in the initalizer of value s which is an alias of String
68-
-- [E007] Type Mismatch Error: <console> ---------------------------------------
68+
-- [E007] Type Mismatch Error: <console>:13:21 ---------------------------------
6969
13 | val z: T = y
7070
| ^
7171
|found: T(y)
@@ -74,19 +74,19 @@ scala> abstract class C {
7474
|where: T is a type in the initalizer of value s which is an alias of String
7575
| T' is a type in method f which is an alias of Int
7676
scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
77-
-- [E008] Member Not Found Error: <console> ------------------------------------
77+
-- [E008] Member Not Found Error: <console>:4:59 -------------------------------
7878
4 |class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
7979
| ^^^^^^^^
8080
| value `barr` is not a member of Foo(foo) - did you mean `foo.bar`?
8181
scala> val x: List[Int] = "foo" :: List(1)
82-
-- [E007] Type Mismatch Error: <console> ---------------------------------------
82+
-- [E007] Type Mismatch Error: <console>:4:19 ----------------------------------
8383
4 |val x: List[Int] = "foo" :: List(1)
8484
| ^^^^^
8585
| found: String($1$)
8686
| required: Int
8787
|
8888
scala> { def f: Int = g; val x: Int = 1; def g: Int = 5; }
89-
-- [E038] Reference Error: <console> -------------------------------------------
89+
-- [E038] Reference Error: <console>:5:15 --------------------------------------
9090
5 |{ def f: Int = g; val x: Int = 1; def g: Int = 5; }
9191
| ^
9292
| `g` is a forward reference extending over the definition of `x`

tests/repl/imports.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ defined module o
77
scala> import o._
88
import o._
99
scala> buf += xs
10-
-- [E007] Type Mismatch Error: <console> ---------------------------------------
10+
-- [E007] Type Mismatch Error: <console>:11:7 ----------------------------------
1111
11 |buf += xs
1212
| ^^
1313
| found: scala.collection.immutable.List[Int](o.xs)
@@ -16,12 +16,12 @@ scala> buf += xs
1616
scala> buf ++= xs
1717
val res1: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)
1818
scala> import util.foo
19-
-- Error: <console> ------------------------------------------------------------
19+
-- Error: <console>:8:12 -------------------------------------------------------
2020
8 |import util.foo
2121
| ^^^
2222
| foo is not a member of util
2323
scala> import util.foo.bar
24-
-- [E008] Member Not Found Error: <console> ------------------------------------
24+
-- [E008] Member Not Found Error: <console>:8:12 -------------------------------
2525
8 |import util.foo.bar
2626
| ^^^^^^^^
2727
| value `foo` is not a member of util.type - did you mean `util.Left`?

tests/repl/overrides.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
scala> class B { override def foo(i: Int): Unit = {}; }
2-
-- [E036] Reference Error: <console> -------------------------------------------
2+
-- [E036] Reference Error: <console>:4:23 --------------------------------------
33
4 |class B { override def foo(i: Int): Unit = {}; }
44
| ^
55
| method foo overrides nothing
@@ -8,7 +8,7 @@ longer explanation available when compiling with `-explain`
88
scala> class A { def foo: Unit = {}; }
99
defined class A
1010
scala> class B extends A { override def foo(i: Int): Unit = {}; }
11-
-- [E037] Reference Error: <console> -------------------------------------------
11+
-- [E037] Reference Error: <console>:5:33 --------------------------------------
1212
5 |class B extends A { override def foo(i: Int): Unit = {}; }
1313
| ^
1414
| method foo has a different signature than the overridden declaration

0 commit comments

Comments
 (0)