From 4a280c588d8f779a6e50d62efb071e2515b00889 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Fri, 2 Jul 2021 14:40:01 +0200 Subject: [PATCH 01/11] add show diagnostics level in REPL warn | err --- compiler/src/dotty/tools/repl/Rendering.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index 17c876661e18..71495d9111d0 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -33,7 +33,7 @@ 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: " } private var myClassLoader: ClassLoader = _ From 095da6c61e70aa0a2f7e8d27803ccaab13ae9332 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Fri, 2 Jul 2021 14:45:13 +0200 Subject: [PATCH 02/11] fix white space --- compiler/src/dotty/tools/repl/Rendering.scala | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index 71495d9111d0..1adef529a1cd 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -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 = s"-- $diagnosticLevel: " + override def posStr(pos: SourcePosition, diagnosticLevel: String, message: Message)(using Context): String = + s"-- $diagnosticLevel: " } private var myClassLoader: ClassLoader = _ From 7dbdcb4c821a6b3e2251ac229d2c83bed9b09c3d Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Fri, 2 Jul 2021 14:54:59 +0200 Subject: [PATCH 03/11] remove trailing blank --- compiler/src/dotty/tools/repl/Rendering.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index 1adef529a1cd..1511fff9495b 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -34,7 +34,7 @@ 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 = - s"-- $diagnosticLevel: " + s"-- $diagnosticLevel:" } private var myClassLoader: ClassLoader = _ From 542e669e16f811d1f4293f25722952bd2977326c Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Fri, 2 Jul 2021 15:21:29 +0200 Subject: [PATCH 04/11] manually tweak first bulk of repl tests failing --- compiler/test-resources/repl/1379 | 1 + compiler/test-resources/repl/errmsgs | 14 ++++++++++++++ compiler/test-resources/repl/errorThenValid | 1 + compiler/test-resources/repl/i1370 | 1 + compiler/test-resources/repl/i2063 | 3 +++ compiler/test-resources/repl/i2213 | 3 ++- compiler/test-resources/repl/i2631 | 1 + compiler/test-resources/repl/i4566 | 1 + compiler/test-resources/repl/i6676 | 5 +++++ compiler/test-resources/repl/i7644 | 4 ++++ compiler/test-resources/repl/i9227 | 1 + compiler/test-resources/repl/overrides | 2 ++ compiler/test-resources/repl/parsing | 13 +++++++------ compiler/test-resources/type-printer/type-mismatch | 1 + 14 files changed, 44 insertions(+), 7 deletions(-) diff --git a/compiler/test-resources/repl/1379 b/compiler/test-resources/repl/1379 index 902d6251a62b..4814370995a0 100644 --- a/compiler/test-resources/repl/1379 +++ b/compiler/test-resources/repl/1379 @@ -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 \ No newline at end of file diff --git a/compiler/test-resources/repl/errmsgs b/compiler/test-resources/repl/errmsgs index e4cb6eca36d4..8e415ed41a88 100644 --- a/compiler/test-resources/repl/errmsgs +++ b/compiler/test-resources/repl/errmsgs @@ -1,35 +1,42 @@ 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) @@ -37,6 +44,7 @@ scala> abstract class C { type T; val x: T; val s: Unit = { type T = String; var | |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) @@ -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 diff --git a/compiler/test-resources/repl/errorThenValid b/compiler/test-resources/repl/errorThenValid index 3aea44b6392d..6f07caed9b0d 100644 --- a/compiler/test-resources/repl/errorThenValid +++ b/compiler/test-resources/repl/errorThenValid @@ -1,4 +1,5 @@ scala> val xs = scala.collection.mutable.ListBuffer[Int] +-- Error: 1 | val xs = scala.collection.mutable.ListBuffer[Int] | ^ | Missing parameter type diff --git a/compiler/test-resources/repl/i1370 b/compiler/test-resources/repl/i1370 index 21193692e355..9ecc6baf05b7 100644 --- a/compiler/test-resources/repl/i1370 +++ b/compiler/test-resources/repl/i1370 @@ -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. diff --git a/compiler/test-resources/repl/i2063 b/compiler/test-resources/repl/i2063 index 2cee5d4fa735..e134c4eb9738 100644 --- a/compiler/test-resources/repl/i2063 +++ b/compiler/test-resources/repl/i2063 @@ -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 diff --git a/compiler/test-resources/repl/i2213 b/compiler/test-resources/repl/i2213 index 93638f03f504..2ff87954dd8f 100644 --- a/compiler/test-resources/repl/i2213 +++ b/compiler/test-resources/repl/i2213 @@ -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 diff --git a/compiler/test-resources/repl/i2631 b/compiler/test-resources/repl/i2631 index f68b430d829d..a1cd56e372e0 100644 --- a/compiler/test-resources/repl/i2631 +++ b/compiler/test-resources/repl/i2631 @@ -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 \ No newline at end of file diff --git a/compiler/test-resources/repl/i4566 b/compiler/test-resources/repl/i4566 index dcc7262a0eaf..40e0d0610579 100644 --- a/compiler/test-resources/repl/i4566 +++ b/compiler/test-resources/repl/i4566 @@ -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 diff --git a/compiler/test-resources/repl/i6676 b/compiler/test-resources/repl/i6676 index 8e7f2c3d22ef..301dd50d1202 100644 --- a/compiler/test-resources/repl/i6676 +++ b/compiler/test-resources/repl/i6676 @@ -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 diff --git a/compiler/test-resources/repl/i7644 b/compiler/test-resources/repl/i7644 index 780b3847bb4e..8ecab9be11f3 100644 --- a/compiler/test-resources/repl/i7644 +++ b/compiler/test-resources/repl/i7644 @@ -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 diff --git a/compiler/test-resources/repl/i9227 b/compiler/test-resources/repl/i9227 index 772325640ff7..c591fa9f1e0c 100644 --- a/compiler/test-resources/repl/i9227 +++ b/compiler/test-resources/repl/i9227 @@ -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 diff --git a/compiler/test-resources/repl/overrides b/compiler/test-resources/repl/overrides index 05ddd3229deb..35dc779bf446 100644 --- a/compiler/test-resources/repl/overrides +++ b/compiler/test-resources/repl/overrides @@ -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 diff --git a/compiler/test-resources/repl/parsing b/compiler/test-resources/repl/parsing index 2b3da45aa537..9c8955f2effc 100644 --- a/compiler/test-resources/repl/parsing +++ b/compiler/test-resources/repl/parsing @@ -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 diff --git a/compiler/test-resources/type-printer/type-mismatch b/compiler/test-resources/type-printer/type-mismatch index 83a84d917113..30bbea0c7050 100644 --- a/compiler/test-resources/type-printer/type-mismatch +++ b/compiler/test-resources/type-printer/type-mismatch @@ -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]) From b605c03d5a5f7420df8aaa516a75bde90867be63 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Fri, 2 Jul 2021 16:03:05 +0200 Subject: [PATCH 05/11] add util to modify repl tests --- repl-test-update/README.md | 4 +++ repl-test-update/build.sbt | 1 + repl-test-update/project/build.properties | 1 + repl-test-update/run-insert-error.scala | 39 +++++++++++++++++++++++ 4 files changed, 45 insertions(+) create mode 100644 repl-test-update/README.md create mode 100644 repl-test-update/build.sbt create mode 100644 repl-test-update/project/build.properties create mode 100644 repl-test-update/run-insert-error.scala diff --git a/repl-test-update/README.md b/repl-test-update/README.md new file mode 100644 index 000000000000..8bc268e375f1 --- /dev/null +++ b/repl-test-update/README.md @@ -0,0 +1,4 @@ +# Small fix to update all repl test-resources + +Made to fix this issue: +https://github.com/lampepfl/dotty/issues/12981 \ No newline at end of file diff --git a/repl-test-update/build.sbt b/repl-test-update/build.sbt new file mode 100644 index 000000000000..a3a7469faf24 --- /dev/null +++ b/repl-test-update/build.sbt @@ -0,0 +1 @@ +scalaVersion := "3.0.0" diff --git a/repl-test-update/project/build.properties b/repl-test-update/project/build.properties new file mode 100644 index 000000000000..9edb75b77c28 --- /dev/null +++ b/repl-test-update/project/build.properties @@ -0,0 +1 @@ +sbt.version=1.5.4 diff --git a/repl-test-update/run-insert-error.scala b/repl-test-update/run-insert-error.scala new file mode 100644 index 000000000000..ca309ea54827 --- /dev/null +++ b/repl-test-update/run-insert-error.scala @@ -0,0 +1,39 @@ +def replTestDir = "../compiler/test-resources/repl" + +def list(dir: String = "."): Vector[String] = + Option(new java.io.File(dir).list).map(_.toVector).getOrElse(Vector()) + +def loadLines(fileName: String, enc: String = "UTF-8"): Vector[String] = + var result = Vector.empty[String] + val source = scala.io.Source.fromFile(fileName, enc) + try result = source.getLines().toVector finally source.close() + result + +def saveString(text: String, fileName: String, enc: String = "UTF-8"): Unit = + val f = new java.io.File(fileName) + val pw = new java.io.PrintWriter(f, enc) + try pw.write(text) finally pw.close() + + +@main +def run_insert_error(): Unit = + for f <- list(replTestDir) do + val fileName = s"$replTestDir/$f" + print(s"\nprocessing: $fileName") + val lines = loadLines(fileName) + var result = Vector[String]() + for i <- lines.indices do + result :+= lines(i) + if lines(i).startsWith("scala>") && + lines.lift(i + 1).map(_.startsWith("1 | ")).getOrElse(false) + then + result :+= "-- Error:" + + val msg = + if lines == result then Console.GREEN + " unmodified" + Console.RESET + else Console.RED + " *** MODIFIED" + Console.RESET + println(msg) + if lines != result then + println("\nbefore ==========>\n" + lines.mkString("\n")) + println("\nafter ==========>\n" + result.mkString("\n")) + saveString(result.mkString("\n"), fileName) \ No newline at end of file From 05a454a22dab30bf2b8becc39d07352a8aa0de56 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Fri, 2 Jul 2021 16:06:10 +0200 Subject: [PATCH 06/11] run utility and then manually tweak Warning --- compiler/test-resources/repl/i4184 | 1 + compiler/test-resources/repl/i4217 | 1 + compiler/test-resources/repl/i5733 | 3 ++- compiler/test-resources/repl/i6474 | 1 + compiler/test-resources/repl/importFromObj | 3 +++ compiler/test-resources/repl/notFound | 4 +++- 6 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/test-resources/repl/i4184 b/compiler/test-resources/repl/i4184 index 385e98014d11..ce407561354d 100644 --- a/compiler/test-resources/repl/i4184 +++ b/compiler/test-resources/repl/i4184 @@ -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 != diff --git a/compiler/test-resources/repl/i4217 b/compiler/test-resources/repl/i4217 index 22964adaf6a7..2015f0041431 100644 --- a/compiler/test-resources/repl/i4217 +++ b/compiler/test-resources/repl/i4217 @@ -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. diff --git a/compiler/test-resources/repl/i5733 b/compiler/test-resources/repl/i5733 index e9afea5e98ec..2a9ce5515467 100644 --- a/compiler/test-resources/repl/i5733 +++ b/compiler/test-resources/repl/i5733 @@ -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 \ No newline at end of file diff --git a/compiler/test-resources/repl/i6474 b/compiler/test-resources/repl/i6474 index 8b11b42859cf..b39fa1b91a75 100644 --- a/compiler/test-resources/repl/i6474 +++ b/compiler/test-resources/repl/i6474 @@ -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] diff --git a/compiler/test-resources/repl/importFromObj b/compiler/test-resources/repl/importFromObj index 144859891519..4b26e59196bd 100644 --- a/compiler/test-resources/repl/importFromObj +++ b/compiler/test-resources/repl/importFromObj @@ -5,6 +5,7 @@ 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]) @@ -12,10 +13,12 @@ scala> buf += xs 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 diff --git a/compiler/test-resources/repl/notFound b/compiler/test-resources/repl/notFound index 99379a89660d..46c700f0412a 100644 --- a/compiler/test-resources/repl/notFound +++ b/compiler/test-resources/repl/notFound @@ -1,8 +1,10 @@ scala> Foo +-- Error: 1 | Foo | ^^^ | Not found: Foo scala> Bar +-- Error: 1 | Bar | ^^^ - | Not found: Bar + | Not found: Bar \ No newline at end of file From 0a5e01d9f76484ef0b50bf56f3901840d98d2b89 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Fri, 2 Jul 2021 17:07:57 +0200 Subject: [PATCH 07/11] update ShadowingTests add "-- Error:" --- compiler/test/dotty/tools/repl/ShadowingTests.scala | 1 + 1 file changed, 1 insertion(+) diff --git a/compiler/test/dotty/tools/repl/ShadowingTests.scala b/compiler/test/dotty/tools/repl/ShadowingTests.scala index 037887602a44..3af6c02cf320 100644 --- a/compiler/test/dotty/tools/repl/ShadowingTests.scala +++ b/compiler/test/dotty/tools/repl/ShadowingTests.scala @@ -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 From 1da59b1d8b91bab3dfb13ae8f42b7f120426e61d Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Fri, 2 Jul 2021 17:08:11 +0200 Subject: [PATCH 08/11] make util recursively traverse dirs --- repl-test-update/run-insert-error.scala | 63 +++++++++++++++---------- 1 file changed, 38 insertions(+), 25 deletions(-) diff --git a/repl-test-update/run-insert-error.scala b/repl-test-update/run-insert-error.scala index ca309ea54827..0bcc8b6fd31c 100644 --- a/repl-test-update/run-insert-error.scala +++ b/repl-test-update/run-insert-error.scala @@ -1,7 +1,7 @@ -def replTestDir = "../compiler/test-resources/repl" +def replTestDir = "../compiler/test-resources" def list(dir: String = "."): Vector[String] = - Option(new java.io.File(dir).list).map(_.toVector).getOrElse(Vector()) + Option(java.io.File(dir).list).map(_.toVector).getOrElse(Vector()) def loadLines(fileName: String, enc: String = "UTF-8"): Vector[String] = var result = Vector.empty[String] @@ -10,30 +10,43 @@ def loadLines(fileName: String, enc: String = "UTF-8"): Vector[String] = result def saveString(text: String, fileName: String, enc: String = "UTF-8"): Unit = - val f = new java.io.File(fileName) - val pw = new java.io.PrintWriter(f, enc) + val f = java.io.File(fileName) + val pw = java.io.PrintWriter(f, enc) try pw.write(text) finally pw.close() +extension (s: String) def isDir: Boolean = java.io.File(s).isDirectory + + +def visitFile(path: String, isModify: Boolean): Unit = + print(s"\nprocessing: $path") + val lines = loadLines(path) + var result = Vector[String]() + for i <- lines.indices do + result :+= lines(i) + if lines(i).startsWith("scala>") && + lines.lift(i + 1).map(_.startsWith("1 | ")).getOrElse(false) + then + result :+= "-- Error:" + + val msg = + if lines == result then Console.GREEN + " unmodified" + Console.RESET + else Console.RED + " *** MODIFIED" + Console.RESET + println(msg) + if lines != result then + println("\nbefore ==========>\n" + lines.mkString("\n")) + println("\nafter ==========>\n" + result.mkString("\n")) + if isModify then + println(s"Writing: $path") + saveString(result.mkString("\n"), path) + +def visitDirRecursively(dirName: String, isModify: Boolean): Unit = + println(s"Enter directory: $dirName") + list(dirName).foreach( f => + val path = s"$dirName/$f" + if path.isDir then visitDirRecursively(path, isModify) + else visitFile(path, isModify) + ) @main -def run_insert_error(): Unit = - for f <- list(replTestDir) do - val fileName = s"$replTestDir/$f" - print(s"\nprocessing: $fileName") - val lines = loadLines(fileName) - var result = Vector[String]() - for i <- lines.indices do - result :+= lines(i) - if lines(i).startsWith("scala>") && - lines.lift(i + 1).map(_.startsWith("1 | ")).getOrElse(false) - then - result :+= "-- Error:" - - val msg = - if lines == result then Console.GREEN + " unmodified" + Console.RESET - else Console.RED + " *** MODIFIED" + Console.RESET - println(msg) - if lines != result then - println("\nbefore ==========>\n" + lines.mkString("\n")) - println("\nafter ==========>\n" + result.mkString("\n")) - saveString(result.mkString("\n"), fileName) \ No newline at end of file +def run_insert_error(isModify: Boolean): Unit = + visitDirRecursively(replTestDir, isModify) From 1778dc72a5441cf29dbfd784b0df82d91cdc2547 Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Fri, 2 Jul 2021 18:54:57 +0200 Subject: [PATCH 09/11] fix indent, capture diff value --- repl-test-update/run-insert-error.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/repl-test-update/run-insert-error.scala b/repl-test-update/run-insert-error.scala index 0bcc8b6fd31c..82827bb8b747 100644 --- a/repl-test-update/run-insert-error.scala +++ b/repl-test-update/run-insert-error.scala @@ -28,11 +28,11 @@ def visitFile(path: String, isModify: Boolean): Unit = then result :+= "-- Error:" - val msg = - if lines == result then Console.GREEN + " unmodified" + Console.RESET - else Console.RED + " *** MODIFIED" + Console.RESET + val (msg, isDiff) = + if lines == result then (Console.GREEN + " unmodified" + Console.RESET, false) + else (Console.RED + " *** MODIFIED" + Console.RESET, true) println(msg) - if lines != result then + if isDiff then println("\nbefore ==========>\n" + lines.mkString("\n")) println("\nafter ==========>\n" + result.mkString("\n")) if isModify then From e83c2f1178405ad34d98acb970669d50b27e28cb Mon Sep 17 00:00:00 2001 From: bjornregnell Date: Tue, 6 Jul 2021 11:49:58 +0200 Subject: [PATCH 10/11] remove update util --- repl-test-update/README.md | 4 -- repl-test-update/build.sbt | 1 - repl-test-update/project/build.properties | 1 - repl-test-update/run-insert-error.scala | 52 ----------------------- 4 files changed, 58 deletions(-) delete mode 100644 repl-test-update/README.md delete mode 100644 repl-test-update/build.sbt delete mode 100644 repl-test-update/project/build.properties delete mode 100644 repl-test-update/run-insert-error.scala diff --git a/repl-test-update/README.md b/repl-test-update/README.md deleted file mode 100644 index 8bc268e375f1..000000000000 --- a/repl-test-update/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# Small fix to update all repl test-resources - -Made to fix this issue: -https://github.com/lampepfl/dotty/issues/12981 \ No newline at end of file diff --git a/repl-test-update/build.sbt b/repl-test-update/build.sbt deleted file mode 100644 index a3a7469faf24..000000000000 --- a/repl-test-update/build.sbt +++ /dev/null @@ -1 +0,0 @@ -scalaVersion := "3.0.0" diff --git a/repl-test-update/project/build.properties b/repl-test-update/project/build.properties deleted file mode 100644 index 9edb75b77c28..000000000000 --- a/repl-test-update/project/build.properties +++ /dev/null @@ -1 +0,0 @@ -sbt.version=1.5.4 diff --git a/repl-test-update/run-insert-error.scala b/repl-test-update/run-insert-error.scala deleted file mode 100644 index 82827bb8b747..000000000000 --- a/repl-test-update/run-insert-error.scala +++ /dev/null @@ -1,52 +0,0 @@ -def replTestDir = "../compiler/test-resources" - -def list(dir: String = "."): Vector[String] = - Option(java.io.File(dir).list).map(_.toVector).getOrElse(Vector()) - -def loadLines(fileName: String, enc: String = "UTF-8"): Vector[String] = - var result = Vector.empty[String] - val source = scala.io.Source.fromFile(fileName, enc) - try result = source.getLines().toVector finally source.close() - result - -def saveString(text: String, fileName: String, enc: String = "UTF-8"): Unit = - val f = java.io.File(fileName) - val pw = java.io.PrintWriter(f, enc) - try pw.write(text) finally pw.close() - -extension (s: String) def isDir: Boolean = java.io.File(s).isDirectory - - -def visitFile(path: String, isModify: Boolean): Unit = - print(s"\nprocessing: $path") - val lines = loadLines(path) - var result = Vector[String]() - for i <- lines.indices do - result :+= lines(i) - if lines(i).startsWith("scala>") && - lines.lift(i + 1).map(_.startsWith("1 | ")).getOrElse(false) - then - result :+= "-- Error:" - - val (msg, isDiff) = - if lines == result then (Console.GREEN + " unmodified" + Console.RESET, false) - else (Console.RED + " *** MODIFIED" + Console.RESET, true) - println(msg) - if isDiff then - println("\nbefore ==========>\n" + lines.mkString("\n")) - println("\nafter ==========>\n" + result.mkString("\n")) - if isModify then - println(s"Writing: $path") - saveString(result.mkString("\n"), path) - -def visitDirRecursively(dirName: String, isModify: Boolean): Unit = - println(s"Enter directory: $dirName") - list(dirName).foreach( f => - val path = s"$dirName/$f" - if path.isDir then visitDirRecursively(path, isModify) - else visitFile(path, isModify) - ) - -@main -def run_insert_error(isModify: Boolean): Unit = - visitDirRecursively(replTestDir, isModify) From e1b51e0d54a3e58bcde35eda784fba6e1b0866cb Mon Sep 17 00:00:00 2001 From: Bjorn Regnell Date: Tue, 6 Jul 2021 12:33:01 +0200 Subject: [PATCH 11/11] Update compiler/src/dotty/tools/repl/Rendering.scala Co-authored-by: Jamie Thompson --- compiler/src/dotty/tools/repl/Rendering.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler/src/dotty/tools/repl/Rendering.scala b/compiler/src/dotty/tools/repl/Rendering.scala index 1511fff9495b..f13e0616d1ec 100644 --- a/compiler/src/dotty/tools/repl/Rendering.scala +++ b/compiler/src/dotty/tools/repl/Rendering.scala @@ -34,7 +34,7 @@ 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 = - s"-- $diagnosticLevel:" + hl(diagnosticLevel)(s"-- $diagnosticLevel:") } private var myClassLoader: ClassLoader = _