Skip to content

Commit a801c15

Browse files
committed
Disallow _ for wildcard arguments of types and use ?
1 parent 699ed87 commit a801c15

File tree

455 files changed

+1205
-1192
lines changed

Some content is hidden

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

455 files changed

+1205
-1192
lines changed

compiler/src/dotty/tools/backend/jvm/ClassfileWriters.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {
186186

187187
private final class DirEntryWriter(base: Path) extends FileWriter {
188188
val builtPaths = new ConcurrentHashMap[Path, java.lang.Boolean]()
189-
val noAttributes = Array.empty[FileAttribute[_]]
189+
val noAttributes = Array.empty[FileAttribute[?]]
190190
private val isWindows = scala.util.Properties.isWin
191191

192192
private def checkName(component: Path): Unit = if (isWindows) {

compiler/src/dotty/tools/backend/jvm/CoreBTypes.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ abstract class CoreBTypesFromSymbols[I <: DottyBackendInterface] extends CoreBTy
138138
lazy val jlStringBuilderRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.lang.StringBuilder])
139139
lazy val jlStringBufferRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.lang.StringBuffer])
140140
lazy val jlCharSequenceRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.lang.CharSequence])
141-
lazy val jlClassRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.lang.Class[_]])
141+
lazy val jlClassRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.lang.Class[?]])
142142
lazy val jlThrowableRef : ClassBType = synchClassBTypeFromSymbol(defn.ThrowableClass)
143143
lazy val jlCloneableRef : ClassBType = synchClassBTypeFromSymbol(defn.JavaCloneableClass)
144144
lazy val jiSerializableRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.io.Serializable])

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, Set[ClassSymb
9393

9494
object DottyBackendInterface {
9595

96-
private def erasureString(clazz: Class[_]): String = {
96+
private def erasureString(clazz: Class[?]): String = {
9797
if (clazz.isArray) "Array[" + erasureString(clazz.getComponentType) + "]"
9898
else clazz.getName
9999
}

compiler/src/dotty/tools/backend/jvm/GenericSignatureVisitor.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ abstract class NestedClassesCollector[T](nestedOnly: Boolean) extends GenericSig
315315
if (annot.values != null) annot.values.asScala foreach visitConstant
316316
}
317317

318-
def visitAnnotations(annots: java.util.List[_ <: AnnotationNode]) = if (annots != null) annots.asScala foreach visitAnnotation
318+
def visitAnnotations(annots: java.util.List[? <: AnnotationNode]) = if (annots != null) annots.asScala foreach visitAnnotation
319319
def visitAnnotationss(annotss: Array[java.util.List[AnnotationNode]]) = if (annotss != null) annotss foreach visitAnnotations
320320

321321
def visitHandle(handle: Handle): Unit = {

compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -1089,7 +1089,7 @@ class JSCodeGen()(using genCtx: Context) {
10891089
val exports = List.newBuilder[jsExportsGen.Exported]
10901090
val jsClassCaptures = List.newBuilder[js.ParamDef]
10911091

1092-
def add(tree: ConstructorTree[_ <: JSCtor]): Unit = {
1092+
def add(tree: ConstructorTree[? <: JSCtor]): Unit = {
10931093
val (e, c) = genJSClassCtorDispatch(tree.ctor.sym,
10941094
tree.ctor.paramsAndInfo, tree.overloadNum)
10951095
exports += e
@@ -1270,7 +1270,7 @@ class JSCodeGen()(using genCtx: Context) {
12701270
* here we use the property from building the trees, that a set of
12711271
* descendants always has a range of overload numbers.
12721272
*/
1273-
def ifOverload(tree: ConstructorTree[_], body: js.Tree): js.Tree = body match {
1273+
def ifOverload(tree: ConstructorTree[?], body: js.Tree): js.Tree = body match {
12741274
case js.Skip() => js.Skip()
12751275

12761276
case body =>

compiler/src/dotty/tools/backend/sjs/ScopedVar.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ object ScopedVar {
2828

2929
implicit def toValue[T](scVar: ScopedVar[T]): T = scVar.get
3030

31-
def withScopedVars[T](ass: Assignment[_]*)(body: => T): T = {
31+
def withScopedVars[T](ass: Assignment[?]*)(body: => T): T = {
3232
val stack = ass.map(_.push())
3333
try body
3434
finally stack.reverse.foreach(_.pop())

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>
242242

243243
/** Does this list contain a named argument tree? */
244244
def hasNamedArg(args: List[Any]): Boolean = args exists isNamedArg
245-
val isNamedArg: Any => Boolean = (arg: Any) => arg.isInstanceOf[Trees.NamedArg[_]]
245+
val isNamedArg: Any => Boolean = (arg: Any) => arg.isInstanceOf[Trees.NamedArg[?]]
246246

247247
/** Is this pattern node a catch-all (wildcard or variable) pattern? */
248248
def isDefaultCase(cdef: CaseDef): Boolean = cdef match {
@@ -1060,7 +1060,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
10601060

10611061
def assertAllPositioned(tree: Tree)(using Context): Unit =
10621062
tree.foreachSubTree {
1063-
case t: WithoutTypeOrPos[_] =>
1063+
case t: WithoutTypeOrPos[?] =>
10641064
case t => assert(t.span.exists, i"$t")
10651065
}
10661066

compiler/src/dotty/tools/dotc/ast/Trees.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object Trees {
3131

3232
/** Property key for backquoted identifiers and definitions */
3333
val Backquoted: Property.StickyKey[Unit] = Property.StickyKey()
34-
34+
3535
val SyntheticUnit: Property.StickyKey[Unit] = Property.StickyKey()
3636

3737
/** Trees take a parameter indicating what the type of their `tpe` field
@@ -932,11 +932,11 @@ object Trees {
932932
def rhs(using Context): Tree[T] = { forceFields(); preRhs.asInstanceOf[Tree[T]] }
933933

934934
def leadingTypeParams(using Context): List[TypeDef[T]] = paramss match
935-
case (tparams @ (tparam: TypeDef[_]) :: _) :: _ => tparams.asInstanceOf[List[TypeDef[T]]]
935+
case (tparams @ (tparam: TypeDef[?]) :: _) :: _ => tparams.asInstanceOf[List[TypeDef[T]]]
936936
case _ => Nil
937937

938938
def trailingParamss(using Context): List[ParamClause[T]] = paramss match
939-
case ((tparam: TypeDef[_]) :: _) :: paramss1 => paramss1
939+
case ((tparam: TypeDef[?]) :: _) :: paramss1 => paramss1
940940
case _ => paramss
941941

942942
def termParamss(using Context): List[List[ValDef[T]]] =

compiler/src/dotty/tools/dotc/config/Feature.scala

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ object Feature:
2626
val dependent = experimental("dependent")
2727
val erasedDefinitions = experimental("erasedDefinitions")
2828
val symbolLiterals = deprecated("symbolLiterals")
29+
val underscoreWildcards = deprecated("underscoreWildcards")
2930
val fewerBraces = experimental("fewerBraces")
3031
val saferExceptions = experimental("saferExceptions")
3132
val clauseInterleaving = experimental("clauseInterleaving")

compiler/src/dotty/tools/dotc/inlines/Inliner.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -649,13 +649,13 @@ class Inliner(val call: tpd.Tree)(using Context):
649649
def treeSize(x: Any): Int =
650650
var siz = 0
651651
x match
652-
case x: Trees.Inlined[_] =>
652+
case x: Trees.Inlined[?] =>
653653
case x: Positioned =>
654654
var i = 0
655655
while i < x.productArity do
656656
siz += treeSize(x.productElement(i))
657657
i += 1
658-
case x: List[_] =>
658+
case x: List[?] =>
659659
var xs = x
660660
while xs.nonEmpty do
661661
siz += treeSize(xs.head)

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

+6-3
Original file line numberDiff line numberDiff line change
@@ -1856,9 +1856,12 @@ object Parsers {
18561856
val start = in.skipToken()
18571857
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
18581858
else
1859-
if sourceVersion.isAtLeast(future) then
1860-
deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead")
1861-
patch(source, Span(in.offset, in.offset + 1), "?")
1859+
if !in.featureEnabled(Feature.underscoreWildcards) then
1860+
report.errorOrMigrationWarning(
1861+
em"`_` is deprecated for wildcard arguments of types: use `?` instead${rewriteNotice(`3.4-migration`)}",
1862+
in.sourcePos(), from = `3.4`)
1863+
if sourceVersion == `3.4-migration` then
1864+
patch(source, Span(in.offset, in.offset + 1), "?")
18621865
val start = in.skipToken()
18631866
typeBounds().withSpan(Span(start, in.lastOffset, start))
18641867
// Allow symbols -_ and +_ through for compatibility with code written using kind-projector in Scala 3 underscore mode.

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
160160
core ~ cs.optionalInfo
161161

162162
private def toTextRetainedElem[T <: Untyped](ref: Tree[T]): Text = ref match
163-
case ref: RefTree[_] if ref.typeOpt.exists =>
163+
case ref: RefTree[?] if ref.typeOpt.exists =>
164164
toTextCaptureRef(ref.typeOpt)
165165
case Apply(fn, Literal(str) :: Nil) if fn.symbol == defn.Caps_capIn =>
166166
s"cap[${str.stringValue}]"

compiler/src/dotty/tools/dotc/reporting/messages.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -2648,7 +2648,7 @@ class ExtensionCanOnlyHaveDefs(mdef: untpd.Tree)(using Context)
26482648
|"""
26492649
}
26502650

2651-
class UnexpectedPatternForSummonFrom(tree: Tree[_])(using Context)
2651+
class UnexpectedPatternForSummonFrom(tree: Tree[?])(using Context)
26522652
extends SyntaxMsg(UnexpectedPatternForSummonFromID) {
26532653
def msg(using Context) = i"Unexpected pattern for summonFrom. Expected ${hl("`x: T`")} or ${hl("`_`")}"
26542654
def explain(using Context) =

compiler/src/dotty/tools/dotc/util/Stats.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ import collection.mutable
3232
hits(name) += n
3333
}
3434

35-
def doRecordSize(fn: String, coll: scala.collection.Iterable[_]): coll.type =
35+
def doRecordSize(fn: String, coll: scala.collection.Iterable[?]): coll.type =
3636
doRecord(fn, coll.size)
3737
coll
3838

compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1779,7 +1779,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
17791779

17801780
def show(using printer: Printer[TypeRepr]): String = printer.show(self)
17811781

1782-
def seal: scala.quoted.Type[_] = self.asType
1782+
def seal: scala.quoted.Type[?] = self.asType
17831783

17841784
def asType: scala.quoted.Type[?] =
17851785
new TypeImpl(Inferred(self), SpliceScope.getCurrent)

compiler/test/dotty/tools/backend/jvm/AsmNode.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ sealed trait AsmNode[+T] {
2828
object AsmNode {
2929
type AsmMethod = AsmNode[MethodNode]
3030
type AsmField = AsmNode[FieldNode]
31-
type AsmMember = AsmNode[_]
31+
type AsmMember = AsmNode[?]
3232

3333
implicit class ClassNodeOps(val node: ClassNode) {
3434
def fieldsAndMethods: List[AsmMember] = {

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ trait DottyBytecodeTest {
202202
assert(succ, msg)
203203
}
204204

205-
private def sameCharacteristics(clazzA: ClassNode, clazzB: ClassNode)(f: AsmNode[_] => String): (Boolean, String) = {
205+
private def sameCharacteristics(clazzA: ClassNode, clazzB: ClassNode)(f: AsmNode[?] => String): (Boolean, String) = {
206206
val ms1 = clazzA.fieldsAndMethods.toIndexedSeq
207207
val ms2 = clazzB.fieldsAndMethods.toIndexedSeq
208208
val name1 = clazzA.name
@@ -254,7 +254,7 @@ trait DottyBytecodeTest {
254254
}
255255
.getOrElse(fail("Could not find constructor for object `Test`"))
256256

257-
private def boxingError(ins: List[_], source: String) =
257+
private def boxingError(ins: List[?], source: String) =
258258
s"""|----------------------------------
259259
|${ins.mkString("\n")}
260260
|----------------------------------
@@ -271,7 +271,7 @@ trait DottyBytecodeTest {
271271
}
272272
.getOrElse(fail("Could not find constructor for object `Test`"))
273273

274-
protected def boxingInstructions(method: MethodNode): (List[_], Boolean) = {
274+
protected def boxingInstructions(method: MethodNode): (List[?], Boolean) = {
275275
val ins = instructionsFromMethod(method)
276276
val boxed = ins.exists {
277277
case Invoke(op, owner, name, desc, itf) =>

0 commit comments

Comments
 (0)