From 43714dd62f7353091aa9be078d58f84035119647 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 7 Nov 2023 09:49:23 +0100 Subject: [PATCH] Deprecation warnings for old syntax (`xs: _*` varargs) --- compiler/src/dotty/tools/dotc/parsing/Parsers.scala | 9 +++++---- tests/neg/i18862-3.4.check | 5 +++++ tests/neg/i18862-3.4.scala | 6 ++++++ tests/neg/i18862-future-migration.scala | 6 ++++++ tests/neg/i18862-future.scala | 4 ++++ 5 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 tests/neg/i18862-3.4.check create mode 100644 tests/neg/i18862-3.4.scala create mode 100644 tests/neg/i18862-future-migration.scala create mode 100644 tests/neg/i18862-future.scala diff --git a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala index 805c25ad40e4..717ec9197e7a 100644 --- a/compiler/src/dotty/tools/dotc/parsing/Parsers.scala +++ b/compiler/src/dotty/tools/dotc/parsing/Parsers.scala @@ -2344,11 +2344,12 @@ object Parsers { val isVarargSplice = location.inArgs && followingIsVararg() in.nextToken() if isVarargSplice then - report.errorOrMigrationWarning( - em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead${rewriteNotice(`future-migration`)}", + report.gradualErrorOrMigrationWarning( + em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead${rewriteNotice(`3.4-migration`)}", in.sourcePos(uscoreStart), - future) - if sourceVersion == `future-migration` then + warnFrom = `3.4`, + errorFrom = future) + if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then patch(source, Span(t.span.end, in.lastOffset), "*") else if opStack.nonEmpty then report.errorOrMigrationWarning( diff --git a/tests/neg/i18862-3.4.check b/tests/neg/i18862-3.4.check new file mode 100644 index 000000000000..b56454feeeaa --- /dev/null +++ b/tests/neg/i18862-3.4.check @@ -0,0 +1,5 @@ +-- Error: tests/neg/i18862-3.4.scala:6:38 ------------------------------------------------------------------------------ +6 |def test(xs: List[Int]): Unit = f(xs: _*) // error: migration warning + | ^ + | The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead + | This construct can be rewritten automatically under -rewrite -source 3.4-migration. diff --git a/tests/neg/i18862-3.4.scala b/tests/neg/i18862-3.4.scala new file mode 100644 index 000000000000..a30c8c8f1a59 --- /dev/null +++ b/tests/neg/i18862-3.4.scala @@ -0,0 +1,6 @@ +//> using options -Werror + +import scala.language.`3.4` + +def f(x: Int*): Unit = () +def test(xs: List[Int]): Unit = f(xs: _*) // error: migration warning diff --git a/tests/neg/i18862-future-migration.scala b/tests/neg/i18862-future-migration.scala new file mode 100644 index 000000000000..ff8ba1c377c3 --- /dev/null +++ b/tests/neg/i18862-future-migration.scala @@ -0,0 +1,6 @@ +//> using options -Werror + +import scala.language.`future-migration` + +def f(x: Int*): Unit = () +def test(xs: List[Int]): Unit = f(xs: _*) // error: migration warning diff --git a/tests/neg/i18862-future.scala b/tests/neg/i18862-future.scala new file mode 100644 index 000000000000..07fc72aef34a --- /dev/null +++ b/tests/neg/i18862-future.scala @@ -0,0 +1,4 @@ +import scala.language.future + +def f(x: Int*): Unit = () +def test(xs: List[Int]): Unit = f(xs: _*) // error: migration error