Skip to content

Commit d7896b5

Browse files
authored
Merge pull request #7144 from dotty-staging/refactor-wildcard
Switch to `?` for wildcard types
2 parents c6367d8 + d821662 commit d7896b5

Some content is hidden

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

57 files changed

+167
-167
lines changed

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ object NavigateAST {
3939
*/
4040
def untypedPath(tree: tpd.Tree, exactMatch: Boolean = false)(implicit ctx: Context): List[Positioned] =
4141
tree match {
42-
case tree: MemberDef[_] =>
42+
case tree: MemberDef[?] =>
4343
untypedPath(tree.span) match {
44-
case path @ (last: DefTree[_]) :: _ => path
44+
case path @ (last: DefTree[?]) :: _ => path
4545
case path if !exactMatch => path
4646
case _ => Nil
4747
}
@@ -75,7 +75,7 @@ object NavigateAST {
7575
val path1 = it.next() match {
7676
case p: Positioned => singlePath(p, path)
7777
case m: untpd.Modifiers => childPath(m.productIterator, path)
78-
case xs: List[_] => childPath(xs.iterator, path)
78+
case xs: List[?] => childPath(xs.iterator, path)
7979
case _ => path
8080
}
8181
if ((path1 ne path) &&
@@ -92,7 +92,7 @@ object NavigateAST {
9292
// our usage of `productIterator` by something in `Positioned` that takes
9393
// care of low-level details like this for us.
9494
p match {
95-
case p: WithLazyField[_] =>
95+
case p: WithLazyField[?] =>
9696
p.forceIfLazy
9797
case _ =>
9898
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ object PluggableTransformers {
6464
else finishIdent(ops(tree, old, c), old, c, ops.next)
6565
6666
override def finishIdent(tree: Tree[T], old: Tree[T], c: Context, plugins: Plugins): Tree[T] = tree match {
67-
case tree: Ident[_] => postIdent(tree, old, c, plugins.IdentOps)
67+
case tree: Ident[?] => postIdent(tree, old, c, plugins.IdentOps)
6868
case _ => postProcess(tree, old, c, plugins)
6969
}
7070
@@ -73,13 +73,13 @@ object PluggableTransformers {
7373
else finishSelect(ops(tree, old, c), old, c, ops.next)
7474
7575
override def finishSelect(tree: Tree[T], old: Tree[T], c: Context, plugins: Plugins): Tree[T] = tree match {
76-
case tree: Select[_] => postSelect(tree, old, c, plugins.SelectOps)
76+
case tree: Select[?] => postSelect(tree, old, c, plugins.SelectOps)
7777
case _ => postProcess(tree, old, c, plugins)
7878
}
7979
8080
protected def postProcess(tree: Tree[T], old: Tree[T], c: Context, plugins: Plugins): Tree[T] = tree match {
81-
case tree: Ident[_] => finishIdent(tree, old, c, plugins)
82-
case tree: Select[_] => finishSelect(tree, old, c, plugins)
81+
case tree: Ident[?] => finishIdent(tree, old, c, plugins)
82+
case tree: Select[?] => finishSelect(tree, old, c, plugins)
8383
}
8484
}
8585
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
128128
x.contains(that)
129129
case m: untpd.Modifiers =>
130130
m.mods.exists(isParent) || m.annotations.exists(isParent)
131-
case xs: List[_] =>
131+
case xs: List[?] =>
132132
xs.exists(isParent)
133133
case _ =>
134134
false
@@ -195,7 +195,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
195195
case m: untpd.Modifiers =>
196196
m.annotations.foreach(check)
197197
m.mods.foreach(check)
198-
case xs: List[_] =>
198+
case xs: List[?] =>
199199
xs.foreach(check)
200200
case _ =>
201201
}

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

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ object Trees {
119119
* - errors were reported
120120
*/
121121
private def checkChildrenTyped(it: Iterator[Any])(implicit ctx: Context): Unit =
122-
if (!this.isInstanceOf[Import[_]])
122+
if (!this.isInstanceOf[Import[?]])
123123
while (it.hasNext)
124124
it.next() match {
125-
case x: Ident[_] => // untyped idents are used in a number of places in typed trees
126-
case x: Tree[_] =>
125+
case x: Ident[?] => // untyped idents are used in a number of places in typed trees
126+
case x: Tree[?] =>
127127
assert(x.hasType || ctx.reporter.errorsReported,
128128
s"$this has untyped child $x")
129-
case xs: List[_] => checkChildrenTyped(xs.iterator)
129+
case xs: List[?] => checkChildrenTyped(xs.iterator)
130130
case _ =>
131131
}
132132

@@ -188,8 +188,8 @@ object Trees {
188188
def treeSize: Int = {
189189
var s = 1
190190
def addSize(elem: Any): Unit = elem match {
191-
case t: Tree[_] => s += t.treeSize
192-
case ts: List[_] => ts foreach addSize
191+
case t: Tree[?] => s += t.treeSize
192+
case ts: List[?] => ts foreach addSize
193193
case _ =>
194194
}
195195
productIterator foreach addSize
@@ -203,18 +203,18 @@ object Trees {
203203

204204
override def toText(printer: Printer): Text = printer.toText(this)
205205

206-
def sameTree(that: Tree[_]): Boolean = {
206+
def sameTree(that: Tree[?]): Boolean = {
207207
def isSame(x: Any, y: Any): Boolean =
208208
x.asInstanceOf[AnyRef].eq(y.asInstanceOf[AnyRef]) || {
209209
x match {
210-
case x: Tree[_] =>
210+
case x: Tree[?] =>
211211
y match {
212-
case y: Tree[_] => x.sameTree(y)
212+
case y: Tree[?] => x.sameTree(y)
213213
case _ => false
214214
}
215-
case x: List[_] =>
215+
case x: List[?] =>
216216
y match {
217-
case y: List[_] => x.corresponds(y)(isSame)
217+
case y: List[?] => x.corresponds(y)(isSame)
218218
case _ => false
219219
}
220220
case _ =>
@@ -771,7 +771,7 @@ object Trees {
771771
type ThisTree[-T >: Untyped] = TypeDef[T]
772772

773773
/** Is this a definition of a class? */
774-
def isClassDef: Boolean = rhs.isInstanceOf[Template[_]]
774+
def isClassDef: Boolean = rhs.isInstanceOf[Template[?]]
775775

776776
def isBackquoted: Boolean = hasAttachment(Backquoted)
777777
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
241241
def hasFlags: Boolean = flags != EmptyFlags
242242
def hasAnnotations: Boolean = annotations.nonEmpty
243243
def hasPrivateWithin: Boolean = privateWithin != tpnme.EMPTY
244-
def hasMod(cls: Class[_]) = mods.exists(_.getClass == cls)
244+
def hasMod(cls: Class[?]) = mods.exists(_.getClass == cls)
245245

246246
private def isEnum = is(Enum, butNot = JavaDefined)
247247

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,11 @@ object CompilerCommand {
6868
val settings = ctx.settings
6969

7070
/** Creates a help message for a subset of options based on cond */
71-
def availableOptionsMsg(cond: Setting[_] => Boolean): String = {
71+
def availableOptionsMsg(cond: Setting[?] => Boolean): String = {
7272
val ss = (ctx.settings.allSettings filter cond).toList sortBy (_.name)
7373
val width = (ss map (_.name.length)).max
7474
def format(s: String) = ("%-" + width + "s") format s
75-
def helpStr(s: Setting[_]) = {
75+
def helpStr(s: Setting[?]) = {
7676
def defaultValue = s.default match {
7777
case _: Int | _: String => s.default.toString
7878
case _ =>
@@ -91,7 +91,7 @@ object CompilerCommand {
9191
ss map helpStr mkString "\n"
9292
}
9393

94-
def createUsageMsg(label: String, shouldExplain: Boolean, cond: Setting[_] => Boolean): String = {
94+
def createUsageMsg(label: String, shouldExplain: Boolean, cond: Setting[?] => Boolean): String = {
9595
val prefix = List(
9696
Some(shortUsage),
9797
Some(explainAdvanced) filter (_ => shouldExplain),
@@ -101,9 +101,9 @@ object CompilerCommand {
101101
prefix + "\n" + availableOptionsMsg(cond)
102102
}
103103

104-
def isStandard(s: Setting[_]): Boolean = !isAdvanced(s) && !isPrivate(s)
105-
def isAdvanced(s: Setting[_]): Boolean = s.name startsWith "-X"
106-
def isPrivate(s: Setting[_]) : Boolean = s.name startsWith "-Y"
104+
def isStandard(s: Setting[?]): Boolean = !isAdvanced(s) && !isPrivate(s)
105+
def isAdvanced(s: Setting[?]): Boolean = s.name startsWith "-X"
106+
def isPrivate(s: Setting[?]) : Boolean = s.name startsWith "-Y"
107107

108108
/** Messages explaining usage and options */
109109
def usageMessage = createUsageMsg("where possible standard", shouldExplain = false, isStandard)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import java.util.jar.Attributes.{ Name => AttributeName }
1010
/** Loads `library.properties` from the jar. */
1111
object Properties extends PropertiesTrait {
1212
protected def propCategory: String = "compiler"
13-
protected def pickJarBasedOn: Class[Option[_]] = classOf[Option[_]]
13+
protected def pickJarBasedOn: Class[Option[?]] = classOf[Option[?]]
1414

1515
/** Scala manifest attributes.
1616
*/
@@ -19,7 +19,7 @@ object Properties extends PropertiesTrait {
1919

2020
trait PropertiesTrait {
2121
protected def propCategory: String // specializes the remainder of the values
22-
protected def pickJarBasedOn: Class[_] // props file comes from jar containing this
22+
protected def pickJarBasedOn: Class[?] // props file comes from jar containing this
2323

2424
/** The name of the properties file */
2525
protected val propFilename: String = "/" + propCategory + ".properties"

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

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ object Settings {
1919
val BooleanTag: ClassTag[Boolean] = ClassTag.Boolean
2020
val IntTag: ClassTag[Int] = ClassTag.Int
2121
val StringTag: ClassTag[String] = ClassTag(classOf[String])
22-
val ListTag: ClassTag[List[_]] = ClassTag(classOf[List[_]])
22+
val ListTag: ClassTag[List[?]] = ClassTag(classOf[List[?]])
2323
val VersionTag: ClassTag[ScalaVersion] = ClassTag(classOf[ScalaVersion])
24-
val OptionTag: ClassTag[Option[_]] = ClassTag(classOf[Option[_]])
24+
val OptionTag: ClassTag[Option[?]] = ClassTag(classOf[Option[?]])
2525
val OutputTag: ClassTag[AbstractFile] = ClassTag(classOf[AbstractFile])
2626

2727
class SettingsState(initialValues: Seq[Any]) {
@@ -65,8 +65,8 @@ object Settings {
6565
choices: Seq[T] = Nil,
6666
prefix: String = "",
6767
aliases: List[String] = Nil,
68-
depends: List[(Setting[_], Any)] = Nil,
69-
propertyClass: Option[Class[_]] = None)(private[Settings] val idx: Int) {
68+
depends: List[(Setting[?], Any)] = Nil,
69+
propertyClass: Option[Class[?]] = None)(private[Settings] val idx: Int) {
7070

7171
private[this] var changed: Boolean = false
7272

@@ -95,7 +95,7 @@ object Settings {
9595
if (choices.isEmpty) ""
9696
else choices match {
9797
case r: Range => s"${r.head}..${r.last}"
98-
case xs: List[_] => xs.mkString(", ")
98+
case xs: List[?] => xs.mkString(", ")
9999
}
100100

101101
def isLegal(arg: Any): Boolean =
@@ -110,7 +110,7 @@ object Settings {
110110
case x: Int => r.head <= x && x <= r.last
111111
case _ => false
112112
}
113-
case xs: List[_] =>
113+
case xs: List[?] =>
114114
xs contains arg
115115
}
116116

@@ -193,12 +193,12 @@ object Settings {
193193

194194
class SettingGroup {
195195

196-
private[this] val _allSettings = new ArrayBuffer[Setting[_]]
197-
def allSettings: Seq[Setting[_]] = _allSettings.toSeq
196+
private[this] val _allSettings = new ArrayBuffer[Setting[?]]
197+
def allSettings: Seq[Setting[?]] = _allSettings.toSeq
198198

199199
def defaultState: SettingsState = new SettingsState(allSettings map (_.default))
200200

201-
def userSetSettings(state: SettingsState): Seq[Setting[_]] =
201+
def userSetSettings(state: SettingsState): Seq[Setting[?]] =
202202
allSettings filterNot (_.isDefaultIn(state))
203203

204204
def toConciseString(state: SettingsState): String =
@@ -207,7 +207,7 @@ object Settings {
207207
private def checkDependencies(state: ArgsSummary): ArgsSummary =
208208
userSetSettings(state.sstate).foldLeft(state)(checkDependenciesOfSetting)
209209

210-
private def checkDependenciesOfSetting(state: ArgsSummary, setting: Setting[_]) =
210+
private def checkDependenciesOfSetting(state: ArgsSummary, setting: Setting[?]) =
211211
setting.depends.foldLeft(state) { (s, dep) =>
212212
val (depSetting, reqValue) = dep
213213
if (depSetting.valueIn(state.sstate) == reqValue) s
@@ -237,7 +237,7 @@ object Settings {
237237
case "--" :: args =>
238238
checkDependencies(stateWithArgs(skipped ++ args))
239239
case x :: _ if x startsWith "-" =>
240-
@tailrec def loop(settings: List[Setting[_]]): ArgsSummary = settings match {
240+
@tailrec def loop(settings: List[Setting[?]]): ArgsSummary = settings match {
241241
case setting :: settings1 =>
242242
val state1 = setting.tryToSet(state)
243243
if (state1 ne state) processArguments(state1, processAll, skipped)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait WrappedProperties extends PropertiesTrait {
1212
def wrap[T](body: => T): Option[T]
1313

1414
protected def propCategory: String = "wrapped"
15-
protected def pickJarBasedOn: Class[_] = this.getClass
15+
protected def pickJarBasedOn: Class[?] = this.getClass
1616

1717
override def propIsSet(name: String): Boolean = wrap(super.propIsSet(name)) exists (x => x)
1818
override def propOrElse(name: String, alt: String): String = wrap(super.propOrElse(name, alt)) getOrElse alt

compiler/src/dotty/tools/dotc/core/Contexts.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ object Contexts {
114114
final def owner: Symbol = _owner
115115

116116
/** The current tree */
117-
private[this] var _tree: Tree[_ >: Untyped]= _
118-
protected def tree_=(tree: Tree[_ >: Untyped]): Unit = _tree = tree
119-
final def tree: Tree[_ >: Untyped] = _tree
117+
private[this] var _tree: Tree[? >: Untyped]= _
118+
protected def tree_=(tree: Tree[? >: Untyped]): Unit = _tree = tree
119+
final def tree: Tree[? >: Untyped] = _tree
120120

121121
/** The current scope */
122122
private[this] var _scope: Scope = _
@@ -337,7 +337,7 @@ object Contexts {
337337
* Note: Currently unused
338338
def enclTemplate: Context = {
339339
var c = this
340-
while (c != NoContext && !c.tree.isInstanceOf[Template[_]] && !c.tree.isInstanceOf[PackageDef[_]])
340+
while (c != NoContext && !c.tree.isInstanceOf[Template[?]] && !c.tree.isInstanceOf[PackageDef[?]])
341341
c = c.outer
342342
c
343343
}*/
@@ -392,15 +392,15 @@ object Contexts {
392392
}
393393

394394
/** The context of expression `expr` seen as a member of a statement sequence */
395-
def exprContext(stat: Tree[_ >: Untyped], exprOwner: Symbol): Context =
395+
def exprContext(stat: Tree[? >: Untyped], exprOwner: Symbol): Context =
396396
if (exprOwner == this.owner) this
397397
else if (untpd.isSuperConstrCall(stat) && this.owner.isClass) superCallContext
398398
else ctx.fresh.setOwner(exprOwner)
399399

400400
/** A new context that summarizes an import statement */
401-
def importContext(imp: Import[_], sym: Symbol): FreshContext = {
401+
def importContext(imp: Import[?], sym: Symbol): FreshContext = {
402402
val impNameOpt = imp.expr match {
403-
case ref: RefTree[_] => Some(ref.name.asTermName)
403+
case ref: RefTree[?] => Some(ref.name.asTermName)
404404
case _ => None
405405
}
406406
ctx.fresh.setImportInfo(
@@ -524,7 +524,7 @@ object Contexts {
524524
def setPeriod(period: Period): this.type = { this.period = period; this }
525525
def setMode(mode: Mode): this.type = { this.mode = mode; this }
526526
def setOwner(owner: Symbol): this.type = { assert(owner != NoSymbol); this.owner = owner; this }
527-
def setTree(tree: Tree[_ >: Untyped]): this.type = { this.tree = tree; this }
527+
def setTree(tree: Tree[? >: Untyped]): this.type = { this.tree = tree; this }
528528
def setScope(scope: Scope): this.type = { this.scope = scope; this }
529529
def setNewScope: this.type = { this.scope = newScope; this }
530530
def setTyperState(typerState: TyperState): this.type = { this.typerState = typerState; this }
@@ -559,7 +559,7 @@ object Contexts {
559559
def setProperty[T](key: Key[T], value: T): this.type =
560560
setMoreProperties(moreProperties.updated(key, value))
561561

562-
def dropProperty(key: Key[_]): this.type =
562+
def dropProperty(key: Key[?]): this.type =
563563
setMoreProperties(moreProperties - key)
564564

565565
def addLocation[T](initial: T): Store.Location[T] = {

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -850,7 +850,7 @@ class Definitions {
850850
* Note that this will also extract the high bound if an
851851
* element type is a wildcard. E.g.
852852
*
853-
* Array[_ <: Array[_ <: Number]]
853+
* Array[? <: Array[? <: Number]]
854854
*
855855
* would match
856856
*
@@ -1218,10 +1218,10 @@ class Definitions {
12181218
private val typeTags = mutable.Map[TypeName, Name]().withDefaultValue(nme.specializedTypeNames.Object)
12191219

12201220
// private val unboxedTypeRef = mutable.Map[TypeName, TypeRef]()
1221-
// private val javaTypeToValueTypeRef = mutable.Map[Class[_], TypeRef]()
1222-
// private val valueTypeNamesToJavaType = mutable.Map[TypeName, Class[_]]()
1221+
// private val javaTypeToValueTypeRef = mutable.Map[Class[?], TypeRef]()
1222+
// private val valueTypeNamesToJavaType = mutable.Map[TypeName, Class[?]]()
12231223

1224-
private def valueTypeRef(name: String, jtype: Class[_], enc: Int, tag: Name): TypeRef = {
1224+
private def valueTypeRef(name: String, jtype: Class[?], enc: Int, tag: Name): TypeRef = {
12251225
val vcls = ctx.requiredClassRef(name)
12261226
valueTypeEnc(vcls.name) = enc
12271227
typeTags(vcls.name) = tag
@@ -1249,8 +1249,8 @@ class Definitions {
12491249
/** The JVM tag for `tp` if it's a primitive, `java.lang.Object` otherwise. */
12501250
def typeTag(tp: Type)(implicit ctx: Context): Name = typeTags(scalaClassName(tp))
12511251

1252-
// /** The `Class[_]` of a primitive value type name */
1253-
// def valueTypeNameToJavaType(name: TypeName)(implicit ctx: Context): Option[Class[_]] =
1252+
// /** The `Class[?]` of a primitive value type name */
1253+
// def valueTypeNameToJavaType(name: TypeName)(implicit ctx: Context): Option[Class[?]] =
12541254
// valueTypeNamesToJavaType.get(if (name.firstPart eq nme.scala_) name.lastPart.toTypeName else name)
12551255

12561256
type PrimitiveClassEnc = Int

compiler/src/dotty/tools/dotc/core/Phases.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ object Phases {
252252
final def genBCodePhase: Phase = myGenBCodePhase
253253

254254
private def setSpecificPhases() = {
255-
def phaseOfClass(pclass: Class[_]) = phases.find(pclass.isInstance).getOrElse(NoPhase)
255+
def phaseOfClass(pclass: Class[?]) = phases.find(pclass.isInstance).getOrElse(NoPhase)
256256

257257
myTyperPhase = phaseOfClass(classOf[FrontEnd])
258258
myPostTyperPhase = phaseOfClass(classOf[PostTyper])
@@ -420,7 +420,7 @@ object Phases {
420420
/** Replace all instances of `oldPhaseClass` in `current` phases
421421
* by the result of `newPhases` applied to the old phase.
422422
*/
423-
def replace(oldPhaseClass: Class[_ <: Phase], newPhases: Phase => List[Phase], current: List[List[Phase]]): List[List[Phase]] =
423+
def replace(oldPhaseClass: Class[? <: Phase], newPhases: Phase => List[Phase], current: List[List[Phase]]): List[List[Phase]] =
424424
current.map(_.flatMap(phase =>
425425
if (oldPhaseClass.isInstance(phase)) newPhases(phase) else phase :: Nil))
426426
}

0 commit comments

Comments
 (0)