Skip to content

Commit e3af2de

Browse files
Deprecation warnings for old syntax: _ type wildcards (#18813)
Based on #18887 First part of #18869 * In `3.4` we emit the deprecation warning and enable the patch with `-rewrite`. * In `future` we emit we make this syntax an error ```scala //> using options -source future def f: F[_] = ??? // error ``` ```diff //> using options -rewrite -source 3.4-migration - def f: F[_] = ??? + def f: F[?] = ??? ```
2 parents 49587e2 + b822bd0 commit e3af2de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+168
-107
lines changed

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1870,9 +1870,15 @@ object Parsers {
18701870
val start = in.skipToken()
18711871
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
18721872
else
1873-
if !inTypeMatchPattern && sourceVersion.isAtLeast(future) then
1874-
deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead")
1875-
patch(source, Span(in.offset, in.offset + 1), "?")
1873+
if !inTypeMatchPattern then
1874+
report.gradualErrorOrMigrationWarning(
1875+
em"`_` is deprecated for wildcard arguments of types: use `?` instead${rewriteNotice(`3.4-migration`)}",
1876+
in.sourcePos(),
1877+
warnFrom = `3.4`,
1878+
errorFrom = future)
1879+
if sourceVersion.isMigrating && sourceVersion.isAtLeast(`3.4-migration`) then
1880+
patch(source, Span(in.offset, in.offset + 1), "?")
1881+
end if
18761882
val start = in.skipToken()
18771883
typeBounds().withSpan(Span(start, in.lastOffset, start))
18781884
// Allow symbols -_ and +_ through for compatibility with code written using kind-projector in Scala 3 underscore mode.
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
//> using options -source:future -deprecation
1+
//> using options -source:3.4-migration
22
scala> type M[X] = X match { case Int => String case _ => Int }
33
scala> type N[X] = X match { case List[_] => Int }

compiler/test-resources/repl/i6643

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
scala> import scala.collection._
22
scala>:type 1
33
Int
4-
scala> object IterableTest { def g[CC[_] <: Iterable[_] with IterableOps[_, _, _]](from: CC[Int]): IterableFactory[CC] = ??? }
4+
scala> object IterableTest { def g[CC[_] <: Iterable[?] with IterableOps[?, ?, ?]](from: CC[Int]): IterableFactory[CC] = ??? }
55
1 warning found
66
-- [E003] Syntax Warning: ------------------------------------------------------
7-
1 | object IterableTest { def g[CC[_] <: Iterable[_] with IterableOps[_, _, _]](from: CC[Int]): IterableFactory[CC] = ??? }
7+
1 | object IterableTest { def g[CC[_] <: Iterable[?] with IterableOps[?, ?, ?]](from: CC[Int]): IterableFactory[CC] = ??? }
88
| ^^^^
99
| with as a type operator has been deprecated; use & instead
1010
|

project/Build.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,8 @@ object Build {
12661266
libraryDependencies += ("org.scalameta" % "mtags-shared_2.13.12" % mtagsVersion % SourceDeps),
12671267
ivyConfigurations += SourceDeps.hide,
12681268
transitiveClassifiers := Seq("sources"),
1269+
scalacOptions ++= Seq("-source", "3.3"), // To avoid fatal migration warnings
12691270
Compile / scalacOptions ++= Seq("-Yexplicit-nulls", "-Ysafe-init"),
1270-
Compile / scalacOptions ++= Seq("-source", "3.3"), // To avoid fatal migration warnings
12711271
Compile / sourceGenerators += Def.task {
12721272
val s = streams.value
12731273
val cacheDir = s.cacheDirectory

sbt-test/compilerReporter/i14576/Test.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,5 @@ object Test:
1010
def f(x: Text) = println(x.str)
1111
f("abc")
1212

13-
// under -source:future, `_` is deprecated for wildcard arguments of types: use `?` instead
14-
val xs: List[_] = Nil
13+
@deprecated("", "") def deprecatedFun(): Unit = ()
14+
deprecatedFun()

scaladoc-testcases/src/tests/exports1.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class A: //unexpected
1616
= 1
1717
type HKT[T[_], X] //expected: final type HKT = [T[_], X] =>> a.HKT[T, X]
1818
= T[X]
19-
type SomeRandomType = (List[_] | Seq[_]) & String //expected: final type SomeRandomType = a.SomeRandomType
19+
type SomeRandomType = (List[?] | Seq[?]) & String //expected: final type SomeRandomType = a.SomeRandomType
2020
def x[T[_], X](x: X): HKT[T, X] //expected: def x[T[_], X](x: X): A.this.HKT[T, X]
2121
= ???
2222
def fn[T, U]: T => U

scaladoc-testcases/src/tests/hkts.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ trait Case14[C[_]]
4646
class SomeClass extends Case14[List]
4747

4848

49-
def method1[E, T](value: List[_ >: E]): Int = 0
49+
def method1[E, T](value: List[? >: E]): Int = 0
5050
def method2[F[+X] <: Option[X], A](fa: F[A]): A = fa.get
5151

5252
import scala.collection.immutable.ArraySeq

scaladoc-testcases/src/tests/snippetTestcase2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package tests
22
package snippetTestcase2
33

44
trait Quotes2[A] {
5-
val r1: r1Module[_] = ???
5+
val r1: r1Module[?] = ???
66
trait r1Module[A] {
77
type X
88
object Y {

scaladoc/src/dotty/tools/scaladoc/ScaladocSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,5 +133,5 @@ class ScaladocSettings extends SettingGroup with AllScalaSettings:
133133
"List of quick links that is displayed in the header of documentation."
134134
)
135135

136-
def scaladocSpecificSettings: Set[Setting[_]] =
136+
def scaladocSpecificSettings: Set[Setting[?]] =
137137
Set(sourceLinks, legacySourceLink, syntax, revision, externalDocumentationMappings, socialLinks, skipById, skipByRegex, deprecatedSkipPackages, docRootContent, snippetCompiler, generateInkuire, defaultTemplate, scastieConfiguration, quickLinks)

scaladoc/src/dotty/tools/scaladoc/site/StaticSiteLoader.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ class StaticSiteLoader(val root: File, val args: Scaladoc.Args)(using StaticSite
144144
(("1900","01","01"), name)
145145

146146
def dateFrom(tf: TemplateFile, default: String = "1900-01-01"): String =
147-
val pageSettings = tf.settings.get("page").collect{ case m: Map[String @unchecked, _] => m }
147+
val pageSettings = tf.settings.get("page").collect{ case m: Map[String @unchecked, ?] => m }
148148
pageSettings.flatMap(_.get("date").collect{ case s: String => s}).getOrElse(default) // blogs without date are last
149149

150150
val posts = List(rootPath.resolve("_posts"))

0 commit comments

Comments
 (0)