Skip to content

Commit

Permalink
Deprecation warnings for old syntax (xs: _* varargs)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 8, 2023
1 parent dc0b43c commit e31e757
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def exec(projectDir: Path, binary: String, arguments: Seq[String], environment:
import scala.jdk.CollectionConverters._
val command = binary +: arguments
log(command.mkString(" "))
val builder = new ProcessBuilder(command: _*).directory(projectDir.toFile).inheritIO()
val builder = new ProcessBuilder(command*).directory(projectDir.toFile).inheritIO()
builder.environment.putAll(environment.asJava)
val process = builder.start()
val exitCode = process.waitFor()
Expand Down
9 changes: 5 additions & 4 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions tests/neg/i18862-3.4.check
Original file line number Diff line number Diff line change
@@ -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.
6 changes: 6 additions & 0 deletions tests/neg/i18862-3.4.scala
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions tests/neg/i18862-future-migration.scala
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions tests/neg/i18862-future.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import scala.language.future

def f(x: Int*): Unit = ()
def test(xs: List[Int]): Unit = f(xs: _*) // error: migration error
4 changes: 2 additions & 2 deletions tests/patmat/exhaustive_heuristics.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ object Test {
// well, in truth, we do rewrite List() to Nil, but otherwise we do nothing
// the full rewrite List(a, b) to a :: b :: Nil, for example is planned (but not sure it's a good idea)
List(true, false) match {
case List(_, _, _:_*) =>
case List(node, _:_*) =>
case List(_, _, _*) =>
case List(node, _*) =>
case Nil =>
}

Expand Down
5 changes: 5 additions & 0 deletions tests/semanticdb/metac.expect
Original file line number Diff line number Diff line change
Expand Up @@ -3153,6 +3153,7 @@ Text => empty
Language => Scala
Symbols => 68 entries
Occurrences => 115 entries
Diagnostics => 1 entries
Synthetics => 3 entries

Symbols:
Expand Down Expand Up @@ -3342,6 +3343,10 @@ Occurrences:
[32:49..32:56): pickOne -> example/SpecialRefinement#pickOne().
[32:57..32:59): as -> example/PickOneRefinement_1#run().(as)

Diagnostics:
[32:60..32:60): [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.

Synthetics:
[15:23..15:34):elems.toMap => *[String, Any]
[15:23..15:34):elems.toMap => *(refl[Tuple2[String, Any]])
Expand Down

0 comments on commit e31e757

Please sign in to comment.