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.

compiler/test-resources/repl/i4566

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
scala> object test { type ::[A, B]; def a: Int :: Int = ???; def b: Int = a }
2+
-- Error:
23
1 | object test { type ::[A, B]; def a: Int :: Int = ???; def b: Int = a }
34
| ^
45
| Found: Int :: Int

compiler/test-resources/repl/i5733

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
scala> abstract class F { def f(arg: Any): Unit; override def toString = "F" }
22
// defined class F
33
scala> val f: F = println
4+
-- Warning:
45
1 | val f: F = println
56
| ^^^^^^^
67
|method println is eta-expanded even though F does not have the @FunctionalInterface annotation.
7-
val f: F = F
8+
val f: F = F

compiler/test-resources/repl/i6474

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ val res0: (Any, Int) = (1,2)
99
scala> ((1, 2): Foo2.T[Int][Int]): Foo2.T[Any][Int]
1010
val res1: (Any, Int) = (1,2)
1111
scala> (1, 2): Foo3.T[Int][Int]
12+
-- Error:
1213
1 | (1, 2): Foo3.T[Int][Int]
1314
| ^^^^^^^^^^^^^^^^
1415
| Missing type parameter for Foo3.T[Int][Int]

compiler/test-resources/repl/i6676

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,24 @@
11
scala> xml"
2+
-- Error:
23
1 | xml"
34
| ^
45
| unclosed string literal
56
scala> xml""
7+
-- Error:
68
1 | xml""
79
| ^^^^^
810
| value xml is not a member of StringContext
911
scala> xml"""
12+
-- Error:
1013
1 | xml"""
1114
| ^
1215
| unclosed multi-line string literal
16+
-- Error:
1317
1 | xml"""
1418
| ^
1519
| unclosed multi-line string literal
1620
scala> s"
21+
-- Error:
1722
1 | s"
1823
| ^
1924
| unclosed string literal

compiler/test-resources/repl/i7644

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11
scala> class T extends CanEqual
2+
-- Error:
23
1 | class T extends CanEqual
34
| ^
45
| Cannot extend sealed trait CanEqual in a different source file
6+
-- Error:
57
1 | class T extends CanEqual
68
| ^^^^^^^^
79
| Missing type parameter for CanEqual
810
scala> class T extends CanEqual
11+
-- Error:
912
1 | class T extends CanEqual
1013
| ^
1114
| Cannot extend sealed trait CanEqual in a different source file
15+
-- Error:
1216
1 | class T extends CanEqual
1317
| ^^^^^^^^
1418
| Missing type parameter for CanEqual

compiler/test-resources/repl/i9227

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
scala> import scala.quoted._; inline def myMacro[T]: Unit = ${ myMacroImpl[T] }; def myMacroImpl[T](using Quotes): Expr[Unit] = '{}; println(myMacro[Int])
2+
-- Error:
23
1 | import scala.quoted._; inline def myMacro[T]: Unit = ${ myMacroImpl[T] }; def myMacroImpl[T](using Quotes): Expr[Unit] = '{}; println(myMacro[Int])
34
| ^^^^^^^^^^^^
45
| Cannot call macro method myMacroImpl defined in the same source file

compiler/test-resources/repl/importFromObj

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,20 @@ scala> object o { val xs = List(1, 2, 3) }
55
// defined object o
66
scala> import o._
77
scala> buf += xs
8+
-- Error:
89
1 | buf += xs
910
| ^^
1011
| Found: (o.xs : List[Int])
1112
| Required: Int
1213
scala> buf ++= xs
1314
val res0: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)
1415
scala> import util.foobar
16+
-- Error:
1517
1 | import util.foobar
1618
| ^^^^^^
1719
| value foobar is not a member of util
1820
scala> import util.foobar.bar
21+
-- Error:
1922
1 | import util.foobar.bar
2023
| ^^^^^^^^^^^
2124
| value foobar is not a member of util

compiler/test-resources/repl/notFound

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
scala> Foo
2+
-- Error:
23
1 | Foo
34
| ^^^
45
| Not found: Foo
56
scala> Bar
7+
-- Error:
68
1 | Bar
79
| ^^^
8-
| Not found: Bar
10+
| Not found: Bar
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
scala> class B { override def foo(i: Int): Unit = {}; }
2+
-- Error:
23
1 | class B { override def foo(i: Int): Unit = {}; }
34
| ^
45
| method foo overrides nothing
56
scala> class A { def foo: Unit = {}; }
67
// defined class A
78
scala> class B extends A { override def foo(i: Int): Unit = {}; }
9+
-- Error:
810
1 | class B extends A { override def foo(i: Int): Unit = {}; }
911
| ^
1012
| method foo has a different signature than the overridden declaration

compiler/test-resources/repl/parsing

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
scala> ;
2-
scala> ;;
3-
scala> 1; 2
1+
scala> ;
2+
scala> ;;
3+
scala> 1; 2
44
val res0: Int = 1
55
val res1: Int = 2
6-
scala> 1;
6+
scala> 1;
77
val res2: Int = 1
8-
scala> 1;; 2
8+
scala> 1;; 2
99
val res3: Int = 1
1010
val res4: Int = 2
11-
scala> }
11+
scala> }
12+
-- Error:
1213
1 | }
1314
| ^
1415
| eof expected, but '}' found

compiler/test-resources/type-printer/type-mismatch

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ scala> case class Foo[A](a: A)
33
scala> Foo(1)
44
val res0: Foo[Int] = Foo(1)
55
scala> val x: Foo[String] = res0
6+
-- Error:
67
1 | val x: Foo[String] = res0
78
| ^^^^
89
| Found: (res0 : Foo[Int])

compiler/test/dotty/tools/repl/ShadowingTests.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class ShadowingTests extends ReplTest(options = ShadowingTests.options):
7878
shadowed = "class C(val c: Int)",
7979
script =
8080
"""|scala> new C().c
81+
|-- Error:
8182
|1 | new C().c
8283
| | ^^^^^^^
8384
| | missing argument for parameter c of constructor C in class C: (c: Int): C

0 commit comments

Comments
 (0)