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 9, 2023
1 parent dc0b43c commit c7bbef5
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 10 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
6 changes: 3 additions & 3 deletions sbt-bridge/test/xsbt/ScalaCompilerForUnitTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ object ScalaCompilerForUnitTesting:
class ScalaCompilerForUnitTesting {

def extractEnteredPhases(srcs: String*): Seq[List[String]] = {
val (tempSrcFiles, Callbacks(_, testProgress)) = compileSrcs(srcs: _*)
val (tempSrcFiles, Callbacks(_, testProgress)) = compileSrcs(srcs*)
val run = testProgress.runs.head
tempSrcFiles.map(src => run.unitPhases(src.id))
}
Expand All @@ -37,7 +37,7 @@ class ScalaCompilerForUnitTesting {
}

def extractProgressPhases(srcs: String*): List[String] = {
val (_, Callbacks(_, testProgress)) = compileSrcs(srcs: _*)
val (_, Callbacks(_, testProgress)) = compileSrcs(srcs*)
testProgress.runs.head.phases
}

Expand Down Expand Up @@ -91,7 +91,7 @@ class ScalaCompilerForUnitTesting {
* Only the names used in the last src file are returned.
*/
def extractUsedNamesFromSrc(sources: String*): Map[String, Set[String]] = {
val (srcFiles, Callbacks(analysisCallback, _)) = compileSrcs(sources: _*)
val (srcFiles, Callbacks(analysisCallback, _)) = compileSrcs(sources*)
srcFiles
.map { srcFile =>
val classesInSrc = analysisCallback.classNames(srcFile).map(_._1)
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 c7bbef5

Please sign in to comment.