From 5a47c530f7c84b67b22240be715bf7baea58d107 Mon Sep 17 00:00:00 2001 From: Ausmarton Zarino Fernandes Date: Sat, 4 Nov 2023 20:27:42 +0000 Subject: [PATCH 1/3] Prevent deprecation of `_` in type patterns --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 3 --- tests/pos-with-compiler-cc/dotc/parsing/Parsers.scala | 3 --- tests/pos/i18808.scala | 8 ++++++++ 3 files changed, 8 insertions(+), 6 deletions(-) create mode 100644 tests/pos/i18808.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index c845ea8f74c7..95ada2670cab 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -1860,9 +1860,6 @@ object Parsers { val start = in.skipToken() Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start)) else - if sourceVersion.isAtLeast(future) then - deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead") - patch(source, Span(in.offset, in.offset + 1), "?") val start = in.skipToken() typeBounds().withSpan(Span(start, in.lastOffset, start)) // Allow symbols -_ and +_ through for compatibility with code written using kind-projector in Scala 3 underscore mode. diff --git a/tests/pos-with-compiler-cc/dotc/parsing/Parsers.scala b/tests/pos-with-compiler-cc/dotc/parsing/Parsers.scala index 5024f2f9e366..83692f4a9c43 100644 --- a/tests/pos-with-compiler-cc/dotc/parsing/Parsers.scala +++ b/tests/pos-with-compiler-cc/dotc/parsing/Parsers.scala @@ -1730,9 +1730,6 @@ object Parsers { val start = in.skipToken() Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start)) else - if sourceVersion.isAtLeast(future) then - deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead") - patch(source, Span(in.offset, in.offset + 1), "?") val start = in.skipToken() typeBounds().withSpan(Span(start, in.lastOffset, start)) // Allow symbols -_ and +_ through for compatibility with code written using kind-projector in Scala 3 underscore mode. diff --git a/tests/pos/i18808.scala b/tests/pos/i18808.scala new file mode 100644 index 000000000000..c17a3dbb67c3 --- /dev/null +++ b/tests/pos/i18808.scala @@ -0,0 +1,8 @@ +//> using options -Werror +import language.future + +type F[X] = X match + case List[_] => Int + +type G[X] = X match + case List[?] => Int \ No newline at end of file From ec18b3b924401b3d6d91da94b0ad3aaac3ebc9b3 Mon Sep 17 00:00:00 2001 From: Ausmarton Zarino Fernandes Date: Sun, 5 Nov 2023 08:26:13 +0000 Subject: [PATCH 2/3] Remove deprecation warnings from existing tests. --- compiler/test-resources/repl/i13208.scala | 7 +------ sbt-test/compilerReporter/i14576/Test.scala | 1 - sbt-test/compilerReporter/i14576/build.sbt | 2 +- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/compiler/test-resources/repl/i13208.scala b/compiler/test-resources/repl/i13208.scala index 61ace43c732d..890116b6a247 100644 --- a/compiler/test-resources/repl/i13208.scala +++ b/compiler/test-resources/repl/i13208.scala @@ -1,8 +1,3 @@ //> using options -source:future -deprecation scala> type M[X] = X match { case Int => String case _ => Int } -scala> type N[X] = X match { case List[_] => Int } -1 warning found --- Deprecation Warning: -------------------------------------------------------- -1 | type N[X] = X match { case List[_] => Int } - | ^ - | `_` is deprecated for wildcard arguments of types: use `?` instead +scala> type N[X] = X match { case List[_] => Int } \ No newline at end of file diff --git a/sbt-test/compilerReporter/i14576/Test.scala b/sbt-test/compilerReporter/i14576/Test.scala index d94a49145f81..c6bc59ad636d 100644 --- a/sbt-test/compilerReporter/i14576/Test.scala +++ b/sbt-test/compilerReporter/i14576/Test.scala @@ -13,5 +13,4 @@ object Test: // private[this] and = _ are deprecated under -source:future private[this] var x: AnyRef = _ - // under -source:future, `_` is deprecated for wildcard arguments of types: use `?` instead val xs: List[_] = Nil diff --git a/sbt-test/compilerReporter/i14576/build.sbt b/sbt-test/compilerReporter/i14576/build.sbt index 9831c23c103e..f04d51a1b909 100644 --- a/sbt-test/compilerReporter/i14576/build.sbt +++ b/sbt-test/compilerReporter/i14576/build.sbt @@ -24,7 +24,7 @@ lazy val root = (project in file(".")) }, assertDeprecationSummary := { assert { - FakePrintWriter.messages.exists(_.contains("there were 3 deprecation warnings; re-run with -deprecation for details")) + FakePrintWriter.messages.exists(_.contains("there were 2 deprecation warnings; re-run with -deprecation for details")) } }, assertNoDeprecationSummary := { From daf661a0aace55cc52ae09b6de16c22c426d2e1e Mon Sep 17 00:00:00 2001 From: Ausmarton Zarino Fernandes Date: Sun, 5 Nov 2023 18:44:55 +0000 Subject: [PATCH 3/3] Revert test case for deprecation of _ in wildcard arguments --- sbt-test/compilerReporter/i14576/Test.scala | 1 + sbt-test/compilerReporter/i14576/build.sbt | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/sbt-test/compilerReporter/i14576/Test.scala b/sbt-test/compilerReporter/i14576/Test.scala index c6bc59ad636d..d94a49145f81 100644 --- a/sbt-test/compilerReporter/i14576/Test.scala +++ b/sbt-test/compilerReporter/i14576/Test.scala @@ -13,4 +13,5 @@ object Test: // private[this] and = _ are deprecated under -source:future private[this] var x: AnyRef = _ + // under -source:future, `_` is deprecated for wildcard arguments of types: use `?` instead val xs: List[_] = Nil diff --git a/sbt-test/compilerReporter/i14576/build.sbt b/sbt-test/compilerReporter/i14576/build.sbt index f04d51a1b909..9831c23c103e 100644 --- a/sbt-test/compilerReporter/i14576/build.sbt +++ b/sbt-test/compilerReporter/i14576/build.sbt @@ -24,7 +24,7 @@ lazy val root = (project in file(".")) }, assertDeprecationSummary := { assert { - FakePrintWriter.messages.exists(_.contains("there were 2 deprecation warnings; re-run with -deprecation for details")) + FakePrintWriter.messages.exists(_.contains("there were 3 deprecation warnings; re-run with -deprecation for details")) } }, assertNoDeprecationSummary := {