Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #12981 add REPL show diagnostics level warn | err #13000

Merged
merged 11 commits into from
Jul 7, 2021
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/repl/Rendering.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ private[repl] class Rendering(parentClassLoader: Option[ClassLoader] = None) {

/** A `MessageRenderer` for the REPL without file positions */
private val messageRenderer = new MessageRendering {
override def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(using Context): String = ""
override def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(using Context): String =
s"-- $diagnosticLevel:"
bjornregnell marked this conversation as resolved.
Show resolved Hide resolved
}

private var myClassLoader: ClassLoader = _
Expand Down
1 change: 1 addition & 0 deletions compiler/test-resources/repl/1379
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
scala> object Foo { val bar = new Object { def baz = 1 }; bar.baz }
-- Error:
1 | object Foo { val bar = new Object { def baz = 1 }; bar.baz }
| ^^^^^^^
| value baz is not a member of Object
14 changes: 14 additions & 0 deletions compiler/test-resources/repl/errmsgs
Original file line number Diff line number Diff line change
@@ -1,42 +1,50 @@
scala> class Inv[T](x: T)
// defined class Inv
scala> val x: List[String] = List(1)
-- Error:
1 | val x: List[String] = List(1)
| ^
| Found: (1 : Int)
| Required: String
scala> val y: List[List[String]] = List(List(1))
-- Error:
1 | val y: List[List[String]] = List(List(1))
| ^
| Found: (1 : Int)
| Required: String
scala> val z: (List[String], List[Int]) = (List(1), List("a"))
-- Error:
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
| ^
| Found: (1 : Int)
| Required: String
-- Error:
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
| ^^^
| Found: ("a" : String)
| Required: Int
scala> val a: Inv[String] = new Inv(new Inv(1))
-- Error:
1 | val a: Inv[String] = new Inv(new Inv(1))
| ^^^^^^^^^^
| Found: Inv[Int]
| Required: String
scala> val b: Inv[String] = new Inv(1)
-- Error:
1 | val b: Inv[String] = new Inv(1)
| ^
| Found: (1 : Int)
| Required: String
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() } }; }
-- Error:
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() } }; }
| ^
|Found: (C.this.x : C.this.T)
|Required: T²
|
|where: T is a type in class C
| T² is a type in the initializer of value s which is an alias of String
-- Error:
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() } }; }
| ^
|Found: (y : T)
Expand All @@ -45,27 +53,33 @@ scala> abstract class C { type T; val x: T; val s: Unit = { type T = String; var
|where: T is a type in the initializer of value s which is an alias of String
| T² is a type in method f which is an alias of Int
scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
-- Error:
1 | class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
| ^^^^^^^^
| value barr is not a member of Foo - did you mean foo.bar?
scala> val x: List[Int] = "foo" :: List(1)
-- Error:
1 | val x: List[Int] = "foo" :: List(1)
| ^^^^^
| Found: ("foo" : String)
| Required: Int
scala> while ((( foo ))) {}
-- Error:
1 | while ((( foo ))) {}
| ^^^
| Not found: foo
scala> val a: iDontExist = 1
-- Error:
1 | val a: iDontExist = 1
| ^^^^^^^^^^
| Not found: type iDontExist
scala> def foo1(x: => Int) = x _
-- Error:
1 | def foo1(x: => Int) = x _
| ^^^
|Only function types can be followed by _ but the current expression has type Int
scala> def foo2(x: => Int): () => Int = x _
-- Error:
1 | def foo2(x: => Int): () => Int = x _
| ^^^
|Only function types can be followed by _ but the current expression has type Int
1 change: 1 addition & 0 deletions compiler/test-resources/repl/errorThenValid
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
scala> val xs = scala.collection.mutable.ListBuffer[Int]
-- Error:
1 | val xs = scala.collection.mutable.ListBuffer[Int]
| ^
| Missing parameter type
Expand Down
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i1370
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
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 {} } }
-- Error:
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 {} } }
| ^^^^^^^^^^
|constructor C1 cannot be accessed as a member of Lives.Private.C1 from class Private.
3 changes: 3 additions & 0 deletions compiler/test-resources/repl/i2063
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
scala> class Foo extends Bar // with one tab
-- Error:
1 | class Foo extends Bar // with one tab
| ^^^
| Not found: type Bar
scala> class Foo extends Bar // with spaces
-- Error:
1 | class Foo extends Bar // with spaces
| ^^^
| Not found: type Bar
scala> class Foo extends Bar // with tabs
-- Error:
1 | class Foo extends Bar // with tabs
| ^^^
| Not found: type Bar
3 changes: 2 additions & 1 deletion compiler/test-resources/repl/i2213
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
scala> def x
-- Error:
1 | def x
| ^
| Missing return type

scala> def x: Int
-- Error:
1 | def x: Int
| ^
|Declaration of method x not allowed here: only classes can have declared but undefined members
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i2631
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
scala> class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } }
-- Error:
1 | class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } }
| ^^^
| foo is not accessible from constructor arguments
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i4184
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ scala> object bar { class Foo }
scala> implicit def eqFoo: CanEqual[foo.Foo, foo.Foo] = CanEqual.derived
def eqFoo: CanEqual[foo.Foo, foo.Foo]
scala> object Bar { new foo.Foo == new bar.Foo }
-- Error:
1 | object Bar { new foo.Foo == new bar.Foo }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| Values of types foo.Foo and bar.Foo cannot be compared with == or !=
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i4217
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
scala> def foo(x: Option[Int]) = x match { case None => }
-- Warning:
1 | def foo(x: Option[Int]) = x match { case None => }
| ^
| match may not be exhaustive.
Expand Down
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i4566
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
scala> object test { type ::[A, B]; def a: Int :: Int = ???; def b: Int = a }
-- Error:
1 | object test { type ::[A, B]; def a: Int :: Int = ???; def b: Int = a }
| ^
| Found: Int :: Int
Expand Down
3 changes: 2 additions & 1 deletion compiler/test-resources/repl/i5733
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
scala> abstract class F { def f(arg: Any): Unit; override def toString = "F" }
// defined class F
scala> val f: F = println
-- Warning:
1 | val f: F = println
| ^^^^^^^
|method println is eta-expanded even though F does not have the @FunctionalInterface annotation.
val f: F = F
val f: F = F
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i6474
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ val res0: (Any, Int) = (1,2)
scala> ((1, 2): Foo2.T[Int][Int]): Foo2.T[Any][Int]
val res1: (Any, Int) = (1,2)
scala> (1, 2): Foo3.T[Int][Int]
-- Error:
1 | (1, 2): Foo3.T[Int][Int]
| ^^^^^^^^^^^^^^^^
| Missing type parameter for Foo3.T[Int][Int]
Expand Down
5 changes: 5 additions & 0 deletions compiler/test-resources/repl/i6676
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
scala> xml"
-- Error:
1 | xml"
| ^
| unclosed string literal
scala> xml""
-- Error:
1 | xml""
| ^^^^^
| value xml is not a member of StringContext
scala> xml"""
-- Error:
1 | xml"""
| ^
| unclosed multi-line string literal
-- Error:
1 | xml"""
| ^
| unclosed multi-line string literal
scala> s"
-- Error:
1 | s"
| ^
| unclosed string literal
4 changes: 4 additions & 0 deletions compiler/test-resources/repl/i7644
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
scala> class T extends CanEqual
-- Error:
1 | class T extends CanEqual
| ^
| Cannot extend sealed trait CanEqual in a different source file
-- Error:
1 | class T extends CanEqual
| ^^^^^^^^
| Missing type parameter for CanEqual
scala> class T extends CanEqual
-- Error:
1 | class T extends CanEqual
| ^
| Cannot extend sealed trait CanEqual in a different source file
-- Error:
1 | class T extends CanEqual
| ^^^^^^^^
| Missing type parameter for CanEqual
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i9227
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
scala> import scala.quoted._; inline def myMacro[T]: Unit = ${ myMacroImpl[T] }; def myMacroImpl[T](using Quotes): Expr[Unit] = '{}; println(myMacro[Int])
-- Error:
1 | import scala.quoted._; inline def myMacro[T]: Unit = ${ myMacroImpl[T] }; def myMacroImpl[T](using Quotes): Expr[Unit] = '{}; println(myMacro[Int])
| ^^^^^^^^^^^^
| Cannot call macro method myMacroImpl defined in the same source file
Expand Down
3 changes: 3 additions & 0 deletions compiler/test-resources/repl/importFromObj
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,20 @@ scala> object o { val xs = List(1, 2, 3) }
// defined object o
scala> import o._
scala> buf += xs
-- Error:
1 | buf += xs
| ^^
| Found: (o.xs : List[Int])
| Required: Int
scala> buf ++= xs
val res0: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)
scala> import util.foobar
-- Error:
1 | import util.foobar
| ^^^^^^
| value foobar is not a member of util
scala> import util.foobar.bar
-- Error:
1 | import util.foobar.bar
| ^^^^^^^^^^^
| value foobar is not a member of util
4 changes: 3 additions & 1 deletion compiler/test-resources/repl/notFound
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
scala> Foo
-- Error:
1 | Foo
| ^^^
| Not found: Foo
scala> Bar
-- Error:
1 | Bar
| ^^^
| Not found: Bar
| Not found: Bar
2 changes: 2 additions & 0 deletions compiler/test-resources/repl/overrides
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
scala> class B { override def foo(i: Int): Unit = {}; }
-- Error:
1 | class B { override def foo(i: Int): Unit = {}; }
| ^
| method foo overrides nothing
scala> class A { def foo: Unit = {}; }
// defined class A
scala> class B extends A { override def foo(i: Int): Unit = {}; }
-- Error:
1 | class B extends A { override def foo(i: Int): Unit = {}; }
| ^
| method foo has a different signature than the overridden declaration
13 changes: 7 additions & 6 deletions compiler/test-resources/repl/parsing
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
scala> ;
scala> ;;
scala> 1; 2
scala> ;
scala> ;;
scala> 1; 2
val res0: Int = 1
val res1: Int = 2
scala> 1;
scala> 1;
val res2: Int = 1
scala> 1;; 2
scala> 1;; 2
val res3: Int = 1
val res4: Int = 2
scala> }
scala> }
-- Error:
1 | }
| ^
| eof expected, but '}' found
1 change: 1 addition & 0 deletions compiler/test-resources/type-printer/type-mismatch
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ scala> case class Foo[A](a: A)
scala> Foo(1)
val res0: Foo[Int] = Foo(1)
scala> val x: Foo[String] = res0
-- Error:
1 | val x: Foo[String] = res0
| ^^^^
| Found: (res0 : Foo[Int])
Expand Down
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/repl/ShadowingTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class ShadowingTests extends ReplTest(options = ShadowingTests.options):
shadowed = "class C(val c: Int)",
script =
"""|scala> new C().c
|-- Error:
|1 | new C().c
| | ^^^^^^^
| | missing argument for parameter c of constructor C in class C: (c: Int): C
Expand Down