Skip to content

Commit

Permalink
REPL: Make sure to call printSummary
Browse files Browse the repository at this point in the history
For example:

    scala> @deprecated("no", "nah") class C; new C
    there were 1 deprecation warning(s); re-run with -deprecation for details
    // defined class C
    val res0: C = C@4273cda6
  • Loading branch information
dwijnand committed Aug 26, 2021
1 parent aac921c commit 8fd820a
Show file tree
Hide file tree
Showing 22 changed files with 40 additions and 0 deletions.
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/repl/ReplCompiler.scala
Expand Up @@ -153,6 +153,7 @@ class ReplCompiler extends Compiler {
private def runCompilationUnit(unit: CompilationUnit, state: State): Result[(CompilationUnit, State)] = {
val ctx = state.context
ctx.run.compileUnits(unit :: Nil)
ctx.run.printSummary()

if (!ctx.reporter.hasErrors) (unit, state).result
else ctx.reporter.removeBufferedMessages(using ctx).errors
Expand Down
1 change: 1 addition & 0 deletions compiler/test-resources/repl/1379
Expand Up @@ -3,3 +3,4 @@ scala> object Foo { val bar = new Object { def baz = 1 }; bar.baz }
1 | object Foo { val bar = new Object { def baz = 1 }; bar.baz }
| ^^^^^^^
| value baz is not a member of Object
1 error found
12 changes: 12 additions & 0 deletions compiler/test-resources/repl/errmsgs
Expand Up @@ -7,13 +7,15 @@ scala> val x: List[String] = List(1)
| Found: (1 : Int)
| Required: String
longer explanation available when compiling with `-explain`
1 error found
scala> val y: List[List[String]] = List(List(1))
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val y: List[List[String]] = List(List(1))
| ^
| Found: (1 : Int)
| Required: String
longer explanation available when compiling with `-explain`
1 error found
scala> val z: (List[String], List[Int]) = (List(1), List("a"))
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val z: (List[String], List[Int]) = (List(1), List("a"))
Expand All @@ -27,20 +29,23 @@ longer explanation available when compiling with `-explain`
| Found: ("a" : String)
| Required: Int
longer explanation available when compiling with `-explain`
2 errors found
scala> val a: Inv[String] = new Inv(new Inv(1))
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val a: Inv[String] = new Inv(new Inv(1))
| ^^^^^^^^^^
| Found: Inv[Int]
| Required: String
longer explanation available when compiling with `-explain`
1 error found
scala> val b: Inv[String] = new Inv(1)
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val b: Inv[String] = new Inv(1)
| ^
| Found: (1 : Int)
| Required: String
longer explanation available when compiling with `-explain`
1 error found
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() } }; }
-- [E007] Type Mismatch 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() } }; }
Expand All @@ -60,39 +65,46 @@ longer explanation available when compiling with `-explain`
|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
longer explanation available when compiling with `-explain`
2 errors found
scala> class Foo() { def bar: Int = 1 }; val foo = new Foo(); foo.barr
-- [E008] Not Found 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?
1 error found
scala> val x: List[Int] = "foo" :: List(1)
-- [E007] Type Mismatch Error: -------------------------------------------------
1 | val x: List[Int] = "foo" :: List(1)
| ^^^^^
| Found: ("foo" : String)
| Required: Int
longer explanation available when compiling with `-explain`
1 error found
scala> while ((( foo ))) {}
-- [E006] Not Found Error: -----------------------------------------------------
1 | while ((( foo ))) {}
| ^^^
| Not found: foo
longer explanation available when compiling with `-explain`
1 error found
scala> val a: iDontExist = 1
-- [E006] Not Found Error: -----------------------------------------------------
1 | val a: iDontExist = 1
| ^^^^^^^^^^
| Not found: type iDontExist
longer explanation available when compiling with `-explain`
1 error found
scala> def foo1(x: => Int) = x _
-- [E099] Syntax Error: --------------------------------------------------------
1 | def foo1(x: => Int) = x _
| ^^^
|Only function types can be followed by _ but the current expression has type Int
longer explanation available when compiling with `-explain`
1 error found
scala> def foo2(x: => Int): () => Int = x _
-- [E099] Syntax Error: --------------------------------------------------------
1 | def foo2(x: => Int): () => Int = x _
| ^^^
|Only function types can be followed by _ but the current expression has type Int
longer explanation available when compiling with `-explain`
1 error found
1 change: 1 addition & 0 deletions compiler/test-resources/repl/errorThenValid
Expand Up @@ -5,5 +5,6 @@ scala> val xs = scala.collection.mutable.ListBuffer[Int]
| Missing parameter type
|
| I could not infer the type of the parameter elems.
1 error found
scala> val xs = scala.collection.mutable.ListBuffer[Int]()
val xs: scala.collection.mutable.ListBuffer[Int] = ListBuffer()
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i13208.default.scala
@@ -1,4 +1,5 @@
scala> try 1
1 warning found
-- [E000] Syntax Warning: ------------------------------------------------------
1 | try 1
| ^^^^^
Expand Down
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i1370
Expand Up @@ -3,3 +3,4 @@ scala> object Lives { class Private { def foo1: Any = new Private.C1; def foo2:
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.
1 error found
3 changes: 3 additions & 0 deletions compiler/test-resources/repl/i2063
Expand Up @@ -4,15 +4,18 @@ scala> class Foo extends Bar // with one tab
| ^^^
| Not found: type Bar
longer explanation available when compiling with `-explain`
1 error found
scala> class Foo extends Bar // with spaces
-- [E006] Not Found Error: -----------------------------------------------------
1 | class Foo extends Bar // with spaces
| ^^^
| Not found: type Bar
longer explanation available when compiling with `-explain`
1 error found
scala> class Foo extends Bar // with tabs
-- [E006] Not Found Error: -----------------------------------------------------
1 | class Foo extends Bar // with tabs
| ^^^
| Not found: type Bar
longer explanation available when compiling with `-explain`
1 error found
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i2213
Expand Up @@ -9,3 +9,4 @@ scala> def x: Int
1 | def x: Int
| ^
|Declaration of method x not allowed here: only classes can have declared but undefined members
1 error found
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i2631
Expand Up @@ -3,3 +3,4 @@ scala> class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } }
1 | class Foo(x : Any) { val foo : Integer = 0; def this() = { this(foo) } }
| ^^^
| foo is not accessible from constructor arguments
1 error found
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i4184
Expand Up @@ -9,3 +9,4 @@ scala> object Bar { new foo.Foo == new bar.Foo }
1 | object Bar { new foo.Foo == new bar.Foo }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
| Values of types foo.Foo and bar.Foo cannot be compared with == or !=
1 error found
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i4217
@@ -1,4 +1,5 @@
scala> def foo(x: Option[Int]) = x match { case None => }
1 warning found
-- [E029] Pattern Match Exhaustivity Warning: ----------------------------------
1 | def foo(x: Option[Int]) = x match { case None => }
| ^
Expand Down
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i4566
Expand Up @@ -5,3 +5,4 @@ scala> object test { type ::[A, B]; def a: Int :: Int = ???; def b: Int = a }
| Found: Int :: Int
| Required: Int
longer explanation available when compiling with `-explain`
1 error found
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i5733
@@ -1,6 +1,7 @@
scala> abstract class F { def f(arg: Any): Unit; override def toString = "F" }
// defined class F
scala> val f: F = println
1 warning found
-- Warning: --------------------------------------------------------------------
1 | val f: F = println
| ^^^^^^^
Expand Down
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i6474
Expand Up @@ -13,6 +13,7 @@ scala> (1, 2): Foo3.T[Int][Int]
1 | (1, 2): Foo3.T[Int][Int]
| ^^^^^^^^^^^^^^^^
| Missing type parameter for Foo3.T[Int][Int]
1 error found
scala> ((1, 2): Foo3.T[Int][Int][Int]): Foo3.T[Any][Int][Int]
val res2: (Any, Int) = (1,2)
scala> object Foo3 { type T[A] = [B] =>> [C] =>> (A, B) }
Expand Down
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i6676
Expand Up @@ -8,6 +8,7 @@ scala> xml""
1 | xml""
| ^^^^^
| value xml is not a member of StringContext
1 error found
scala> xml"""
-- Error: ----------------------------------------------------------------------
1 | xml"""
Expand Down
2 changes: 2 additions & 0 deletions compiler/test-resources/repl/i7644
Expand Up @@ -8,6 +8,7 @@ longer explanation available when compiling with `-explain`
1 | class T extends CanEqual
| ^^^^^^^^
| Missing type parameter for CanEqual
2 errors found
scala> class T extends CanEqual
-- [E112] Syntax Error: --------------------------------------------------------
1 | class T extends CanEqual
Expand All @@ -18,3 +19,4 @@ longer explanation available when compiling with `-explain`
1 | class T extends CanEqual
| ^^^^^^^^
| Missing type parameter for CanEqual
2 errors found
1 change: 1 addition & 0 deletions compiler/test-resources/repl/i9227
Expand Up @@ -4,3 +4,4 @@ scala> import scala.quoted._; inline def myMacro[T]: Unit = ${ myMacroImpl[T] };
| ^^^^^^^^^^^^
| Cannot call macro method myMacroImpl defined in the same source file
| This location contains code that was inlined from rs$line$1:1
1 error found
3 changes: 3 additions & 0 deletions compiler/test-resources/repl/importFromObj
Expand Up @@ -11,15 +11,18 @@ scala> buf += xs
| Found: (o.xs : List[Int])
| Required: Int
longer explanation available when compiling with `-explain`
1 error found
scala> buf ++= xs
val res0: scala.collection.mutable.ListBuffer[Int] = ListBuffer(1, 2, 3)
scala> import util.foobar
-- [E008] Not Found Error: -----------------------------------------------------
1 | import util.foobar
| ^^^^^^
| value foobar is not a member of util
1 error found
scala> import util.foobar.bar
-- [E008] Not Found Error: -----------------------------------------------------
1 | import util.foobar.bar
| ^^^^^^^^^^^
| value foobar is not a member of util
1 error found
2 changes: 2 additions & 0 deletions compiler/test-resources/repl/notFound
Expand Up @@ -4,9 +4,11 @@ scala> Foo
| ^^^
| Not found: Foo
longer explanation available when compiling with `-explain`
1 error found
scala> Bar
-- [E006] Not Found Error: -----------------------------------------------------
1 | Bar
| ^^^
| Not found: Bar
longer explanation available when compiling with `-explain`
1 error found
2 changes: 2 additions & 0 deletions compiler/test-resources/repl/overrides
Expand Up @@ -4,6 +4,7 @@ scala> class B { override def foo(i: Int): Unit = {}; }
| ^
| method foo overrides nothing
longer explanation available when compiling with `-explain`
1 error found
scala> class A { def foo: Unit = {}; }
// defined class A
scala> class B extends A { override def foo(i: Int): Unit = {}; }
Expand All @@ -12,3 +13,4 @@ scala> class B extends A { override def foo(i: Int): Unit = {}; }
| ^
| method foo has a different signature than the overridden declaration
longer explanation available when compiling with `-explain`
1 error found
1 change: 1 addition & 0 deletions compiler/test-resources/type-printer/type-mismatch
Expand Up @@ -9,3 +9,4 @@ scala> val x: Foo[String] = res0
| Found: (res0 : Foo[Int])
| Required: Foo[String]
longer explanation available when compiling with `-explain`
1 error found
1 change: 1 addition & 0 deletions compiler/test/dotty/tools/repl/ShadowingTests.scala
Expand Up @@ -82,6 +82,7 @@ class ShadowingTests extends ReplTest(options = ShadowingTests.options):
|1 | new C().c
| | ^^^^^^^
| | missing argument for parameter c of constructor C in class C: (c: Int): C
|1 error found
|
|scala> new C(13).c
|val res0: Int = 13
Expand Down

0 comments on commit 8fd820a

Please sign in to comment.