Skip to content

Commit a58a48a

Browse files
authored
Merge pull request #13000 from bjornregnell/master
fix #12981 add REPL show diagnostics level warn | err
2 parents 6011847 + e1b51e0 commit a58a48a

File tree

22 files changed

+58
-10
lines changed

22 files changed

+58
-10
lines changed

compiler/src/dotty/tools/repl/Rendering.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {
3333

3434
/** A `MessageRenderer` for the REPL without file positions */
3535
private val messageRenderer = new MessageRendering {
36-
override def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(using Context): String = ""
36+
override def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(using Context): String =
37+
hl(diagnosticLevel)(s"-- $diagnosticLevel:")
3738
}
3839

3940
private var myClassLoader: ClassLoader = _

compiler/test-resources/repl/1379

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
scala> object Foo { val bar = new Object { def baz = 1 }; bar.baz }
2+
-- Error:
23
1 | object Foo { val bar = new Object { def baz = 1 }; bar.baz }
34
| ^^^^^^^
45
| value baz is not a member of Object

compiler/test-resources/repl/errmsgs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
11
scala> class Inv[T](x: T)
22
// defined class Inv
33
scala> val x: List[String] = List(1)
4+
-- Error:
45
1 | val x: List[String] = List(1)
56
| ^
67
| Found: (1 : Int)
78
| Required: String
89
scala> val y: List[List[String]] = List(List(1))
10+
-- Error:
911
1 | val y: List[List[String]] = List(List(1))
1012
| ^
1113
| Found: (1 : Int)
1214
| Required: String
1315
scala> val z: (List[String], List[Int]) = (List(1), List("a"))
16+
-- Error:
1417
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
1518
| ^
1619
| Found: (1 : Int)
1720
| Required: String
21+
-- Error:
1822
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
1923
| ^^^
2024
| Found: ("a" : String)
2125
| Required: Int
2226
scala> val a: Inv[String] = new Inv(new Inv(1))
27+
-- Error:
2328
1 | val a: Inv[String] = new Inv(new Inv(1))
2429
| ^^^^^^^^^^
2530
| Found: Inv[Int]
2631
| Required: String
2732
scala> val b: Inv[String] = new Inv(1)
33+
-- Error:
2834
1 | val b: Inv[String] = new Inv(1)
2935
| ^
3036
| Found: (1 : Int)
3137
| Required: String
3238
scala> abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
39+
-- Error:
3340
1 | abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
3441
| ^
3542
|Found: (C.this.x : C.this.T)
3643
|Required: T²
3744
|
3845
|where: T is a type in class C
3946
| T² is a type in the initializer of value s which is an alias of String
47+
-- Error:
4048
1 | abstract class C { type T; val x: T; val s: Unit = { type T = String; var y: T = x; locally { def f() = { type T = Int; val z: T = y }; f() } }; }
4149
| ^
4250
|Found: (y : T)
@@ -45,27 +53,33 @@ scala> abstract class C { type T; val x: T; val s: Unit = { type T = String; var
4553
|where: T is a type in the initializer of value s which is an alias of String
4654
| T² is a type in method f which is an alias of Int
4755
scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
56+
-- Error:
4857
1 | class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
4958
| ^^^^^^^^
5059
| value barr is not a member of Foo - did you mean foo.bar?
5160
scala> val x: List[Int] = "foo" :: List(1)
61+
-- Error:
5262
1 | val x: List[Int] = "foo" :: List(1)
5363
| ^^^^^
5464
| Found: ("foo" : String)
5565
| Required: Int
5666
scala> while ((( foo ))) {}
67+
-- Error:
5768
1 | while ((( foo ))) {}
5869
| ^^^
5970
| Not found: foo
6071
scala> val a: iDontExist = 1
72+
-- Error:
6173
1 | val a: iDontExist = 1
6274
| ^^^^^^^^^^
6375
| Not found: type iDontExist
6476
scala> def foo1(x: => Int) = x _
77+
-- Error:
6578
1 | def foo1(x: => Int) = x _
6679
| ^^^
6780
|Only function types can be followed by _ but the current expression has type Int
6881
scala> def foo2(x: => Int): () => Int = x _
82+
-- Error:
6983
1 | def foo2(x: => Int): () => Int = x _
7084
| ^^^
7185
|Only function types can be followed by _ but the current expression has type Int

compiler/test-resources/repl/errorThenValid

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
scala> val xs = scala.collection.mutable.ListBuffer[Int]
2+
-- Error:
23
1 | val xs = scala.collection.mutable.ListBuffer[Int]
34
| ^
45
| Missing parameter type

compiler/test-resources/repl/i1370

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
scala> object Lives { class Private { def foo1: Any = new Private.C1; def foo2: Any = new Private.C2 }; object Private { class C1 private {}; private class C2 {} } }
2+
-- Error:
23
1 | object Lives { class Private { def foo1: Any = new Private.C1; def foo2: Any = new Private.C2 }; object Private { class C1 private {}; private class C2 {} } }
34
| ^^^^^^^^^^
45
|constructor C1 cannot be accessed as a member of Lives.Private.C1 from class Private.

compiler/test-resources/repl/i2063

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
scala> class Foo extends Bar // with one tab
2+
-- Error:
23
1 | class Foo extends Bar // with one tab
34
| ^^^
45
| Not found: type Bar
56
scala> class Foo extends Bar // with spaces
7+
-- Error:
68
1 | class Foo extends Bar // with spaces
79
| ^^^
810
| Not found: type Bar
911
scala> class Foo extends Bar // with tabs
12+
-- Error:
1013
1 | class Foo extends Bar // with tabs
1114
| ^^^
1215
| Not found: type Bar

compiler/test-resources/repl/i2213

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
scala> def x
2+
-- Error:
23
1 | def x
34
| ^
45
| Missing return type
5-
66
scala> def x: Int
7+
-- Error:
78
1 | def x: Int
89
| ^
910
|Declaration of method x not allowed here: only classes can have declared but undefined members

compiler/test-resources/repl/i2631

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
scala> class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } }
2+
-- Error:
23
1 | class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } }
34
| ^^^
45
| foo is not accessible from constructor arguments

compiler/test-resources/repl/i4184

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ scala> object bar { class Foo }
55
scala> implicit def eqFoo: CanEqual[foo.Foo, foo.Foo] = CanEqual.derived
66
def eqFoo: CanEqual[foo.Foo, foo.Foo]
77
scala> object Bar { new foo.Foo == new bar.Foo }
8+
-- Error:
89
1 | object Bar { new foo.Foo == new bar.Foo }
910
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
1011
| Values of types foo.Foo and bar.Foo cannot be compared with == or !=

compiler/test-resources/repl/i4217

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
scala> def foo(x: Option[Int]) = x match { case None => }
2+
-- Warning:
23
1 | def foo(x: Option[Int]) = x match { case None => }
34
| ^
45
| match may not be exhaustive.

0 commit comments

Comments
 (0)