Skip to content

Commit c7bbef5

Browse files
committed
Deprecation warnings for old syntax (xs: _* varargs)
1 parent dc0b43c commit c7bbef5

File tree

9 files changed

+37
-10
lines changed

9 files changed

+37
-10
lines changed

community-build/src/scala/dotty/communitybuild/projects.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def exec(projectDir: Path, binary: String, arguments: Seq[String], environment:
2525
import scala.jdk.CollectionConverters._
2626
val command = binary +: arguments
2727
log(command.mkString(" "))
28-
val builder = new ProcessBuilder(command: _*).directory(projectDir.toFile).inheritIO()
28+
val builder = new ProcessBuilder(command*).directory(projectDir.toFile).inheritIO()
2929
builder.environment.putAll(environment.asJava)
3030
val process = builder.start()
3131
val exitCode = process.waitFor()

compiler/src/dotty/tools/dotc/parsing/Parsers.scala

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2344,11 +2344,12 @@ object Parsers {
23442344
val isVarargSplice = location.inArgs && followingIsVararg()
23452345
in.nextToken()
23462346
if isVarargSplice then
2347-
report.errorOrMigrationWarning(
2348-
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead${rewriteNotice(`future-migration`)}",
2347+
report.gradualErrorOrMigrationWarning(
2348+
em"The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead${rewriteNotice(`3.4-migration`)}",
23492349
in.sourcePos(uscoreStart),
2350-
future)
2351-
if sourceVersion == `future-migration` then
2350+
warnFrom = `3.4`,
2351+
errorFrom = future)
2352+
if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
23522353
patch(source, Span(t.span.end, in.lastOffset), "*")
23532354
else if opStack.nonEmpty then
23542355
report.errorOrMigrationWarning(

sbt-bridge/test/xsbt/ScalaCompilerForUnitTesting.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ object ScalaCompilerForUnitTesting:
2525
class ScalaCompilerForUnitTesting {
2626

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

3939
def extractProgressPhases(srcs: String*): List[String] = {
40-
val (_, Callbacks(_, testProgress)) = compileSrcs(srcs: _*)
40+
val (_, Callbacks(_, testProgress)) = compileSrcs(srcs*)
4141
testProgress.runs.head.phases
4242
}
4343

@@ -91,7 +91,7 @@ class ScalaCompilerForUnitTesting {
9191
* Only the names used in the last src file are returned.
9292
*/
9393
def extractUsedNamesFromSrc(sources: String*): Map[String, Set[String]] = {
94-
val (srcFiles, Callbacks(analysisCallback, _)) = compileSrcs(sources: _*)
94+
val (srcFiles, Callbacks(analysisCallback, _)) = compileSrcs(sources*)
9595
srcFiles
9696
.map { srcFile =>
9797
val classesInSrc = analysisCallback.classNames(srcFile).map(_._1)

tests/neg/i18862-3.4.check

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-- Error: tests/neg/i18862-3.4.scala:6:38 ------------------------------------------------------------------------------
2+
6 |def test(xs: List[Int]): Unit = f(xs: _*) // error: migration warning
3+
| ^
4+
| The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead
5+
| This construct can be rewritten automatically under -rewrite -source 3.4-migration.

tests/neg/i18862-3.4.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//> using options -Werror
2+
3+
import scala.language.`3.4`
4+
5+
def f(x: Int*): Unit = ()
6+
def test(xs: List[Int]): Unit = f(xs: _*) // error: migration warning
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
//> using options -Werror
2+
3+
import scala.language.`future-migration`
4+
5+
def f(x: Int*): Unit = ()
6+
def test(xs: List[Int]): Unit = f(xs: _*) // error: migration warning

tests/neg/i18862-future.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import scala.language.future
2+
3+
def f(x: Int*): Unit = ()
4+
def test(xs: List[Int]): Unit = f(xs: _*) // error: migration error

tests/patmat/exhaustive_heuristics.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ object Test {
1818
// well, in truth, we do rewrite List() to Nil, but otherwise we do nothing
1919
// the full rewrite List(a, b) to a :: b :: Nil, for example is planned (but not sure it's a good idea)
2020
List(true, false) match {
21-
case List(_, _, _:_*) =>
22-
case List(node, _:_*) =>
21+
case List(_, _, _*) =>
22+
case List(node, _*) =>
2323
case Nil =>
2424
}
2525

tests/semanticdb/metac.expect

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3153,6 +3153,7 @@ Text => empty
31533153
Language => Scala
31543154
Symbols => 68 entries
31553155
Occurrences => 115 entries
3156+
Diagnostics => 1 entries
31563157
Synthetics => 3 entries
31573158

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

3346+
Diagnostics:
3347+
[32:60..32:60): [warning] The syntax `x: _*` is no longer supported for vararg splices; use `x*` instead
3348+
This construct can be rewritten automatically under -rewrite -source 3.4-migration.
3349+
33453350
Synthetics:
33463351
[15:23..15:34):elems.toMap => *[String, Any]
33473352
[15:23..15:34):elems.toMap => *(refl[Tuple2[String, Any]])

0 commit comments

Comments
 (0)