Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch to ? for wildcard types #7144

Merged
merged 3 commits into from
Sep 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/NavigateAST.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ object NavigateAST {
*/
def untypedPath(tree: tpd.Tree, exactMatch: Boolean = false)(implicit ctx: Context): List[Positioned] =
tree match {
case tree: MemberDef[_] =>
case tree: MemberDef[?] =>
untypedPath(tree.span) match {
case path @ (last: DefTree[_]) :: _ => path
case path @ (last: DefTree[?]) :: _ => path
case path if !exactMatch => path
case _ => Nil
}
Expand Down Expand Up @@ -75,7 +75,7 @@ object NavigateAST {
val path1 = it.next() match {
case p: Positioned => singlePath(p, path)
case m: untpd.Modifiers => childPath(m.productIterator, path)
case xs: List[_] => childPath(xs.iterator, path)
case xs: List[?] => childPath(xs.iterator, path)
case _ => path
}
if ((path1 ne path) &&
Expand All @@ -92,7 +92,7 @@ object NavigateAST {
// our usage of `productIterator` by something in `Positioned` that takes
// care of low-level details like this for us.
p match {
case p: WithLazyField[_] =>
case p: WithLazyField[?] =>
p.forceIfLazy
case _ =>
}
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/PluggableTransformers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ object PluggableTransformers {
else finishIdent(ops(tree, old, c), old, c, ops.next)

override def finishIdent(tree: Tree[T], old: Tree[T], c: Context, plugins: Plugins): Tree[T] = tree match {
case tree: Ident[_] => postIdent(tree, old, c, plugins.IdentOps)
case tree: Ident[?] => postIdent(tree, old, c, plugins.IdentOps)
case _ => postProcess(tree, old, c, plugins)
}

Expand All @@ -73,13 +73,13 @@ object PluggableTransformers {
else finishSelect(ops(tree, old, c), old, c, ops.next)

override def finishSelect(tree: Tree[T], old: Tree[T], c: Context, plugins: Plugins): Tree[T] = tree match {
case tree: Select[_] => postSelect(tree, old, c, plugins.SelectOps)
case tree: Select[?] => postSelect(tree, old, c, plugins.SelectOps)
case _ => postProcess(tree, old, c, plugins)
}

protected def postProcess(tree: Tree[T], old: Tree[T], c: Context, plugins: Plugins): Tree[T] = tree match {
case tree: Ident[_] => finishIdent(tree, old, c, plugins)
case tree: Select[_] => finishSelect(tree, old, c, plugins)
case tree: Ident[?] => finishIdent(tree, old, c, plugins)
case tree: Select[?] => finishSelect(tree, old, c, plugins)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/Positioned.scala
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
x.contains(that)
case m: untpd.Modifiers =>
m.mods.exists(isParent) || m.annotations.exists(isParent)
case xs: List[_] =>
case xs: List[?] =>
xs.exists(isParent)
case _ =>
false
Expand Down Expand Up @@ -195,7 +195,7 @@ abstract class Positioned(implicit @constructorOnly src: SourceFile) extends Pro
case m: untpd.Modifiers =>
m.annotations.foreach(check)
m.mods.foreach(check)
case xs: List[_] =>
case xs: List[?] =>
xs.foreach(check)
case _ =>
}
Expand Down
24 changes: 12 additions & 12 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,14 @@ object Trees {
* - errors were reported
*/
private def checkChildrenTyped(it: Iterator[Any])(implicit ctx: Context): Unit =
if (!this.isInstanceOf[Import[_]])
if (!this.isInstanceOf[Import[?]])
while (it.hasNext)
it.next() match {
case x: Ident[_] => // untyped idents are used in a number of places in typed trees
case x: Tree[_] =>
case x: Ident[?] => // untyped idents are used in a number of places in typed trees
case x: Tree[?] =>
assert(x.hasType || ctx.reporter.errorsReported,
s"$this has untyped child $x")
case xs: List[_] => checkChildrenTyped(xs.iterator)
case xs: List[?] => checkChildrenTyped(xs.iterator)
case _ =>
}

Expand Down Expand Up @@ -188,8 +188,8 @@ object Trees {
def treeSize: Int = {
var s = 1
def addSize(elem: Any): Unit = elem match {
case t: Tree[_] => s += t.treeSize
case ts: List[_] => ts foreach addSize
case t: Tree[?] => s += t.treeSize
case ts: List[?] => ts foreach addSize
case _ =>
}
productIterator foreach addSize
Expand All @@ -203,18 +203,18 @@ object Trees {

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

def sameTree(that: Tree[_]): Boolean = {
def sameTree(that: Tree[?]): Boolean = {
def isSame(x: Any, y: Any): Boolean =
x.asInstanceOf[AnyRef].eq(y.asInstanceOf[AnyRef]) || {
x match {
case x: Tree[_] =>
case x: Tree[?] =>
y match {
case y: Tree[_] => x.sameTree(y)
case y: Tree[?] => x.sameTree(y)
case _ => false
}
case x: List[_] =>
case x: List[?] =>
y match {
case y: List[_] => x.corresponds(y)(isSame)
case y: List[?] => x.corresponds(y)(isSame)
case _ => false
}
case _ =>
Expand Down Expand Up @@ -771,7 +771,7 @@ object Trees {
type ThisTree[-T >: Untyped] = TypeDef[T]

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

def isBackquoted: Boolean = hasAttachment(Backquoted)
}
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/untpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
def hasFlags: Boolean = flags != EmptyFlags
def hasAnnotations: Boolean = annotations.nonEmpty
def hasPrivateWithin: Boolean = privateWithin != tpnme.EMPTY
def hasMod(cls: Class[_]) = mods.exists(_.getClass == cls)
def hasMod(cls: Class[?]) = mods.exists(_.getClass == cls)

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

Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/config/CompilerCommand.scala
Original file line number Diff line number Diff line change
Expand Up @@ -68,11 +68,11 @@ object CompilerCommand {
val settings = ctx.settings

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

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

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

/** Messages explaining usage and options */
def usageMessage = createUsageMsg("where possible standard", shouldExplain = false, isStandard)
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/config/Properties.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import java.util.jar.Attributes.{ Name => AttributeName }
/** Loads `library.properties` from the jar. */
object Properties extends PropertiesTrait {
protected def propCategory: String = "compiler"
protected def pickJarBasedOn: Class[Option[_]] = classOf[Option[_]]
protected def pickJarBasedOn: Class[Option[?]] = classOf[Option[?]]

/** Scala manifest attributes.
*/
Expand All @@ -19,7 +19,7 @@ object Properties extends PropertiesTrait {

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

/** The name of the properties file */
protected val propFilename: String = "/" + propCategory + ".properties"
Expand Down
22 changes: 11 additions & 11 deletions compiler/src/dotty/tools/dotc/config/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ object Settings {
val BooleanTag: ClassTag[Boolean] = ClassTag.Boolean
val IntTag: ClassTag[Int] = ClassTag.Int
val StringTag: ClassTag[String] = ClassTag(classOf[String])
val ListTag: ClassTag[List[_]] = ClassTag(classOf[List[_]])
val ListTag: ClassTag[List[?]] = ClassTag(classOf[List[?]])
val VersionTag: ClassTag[ScalaVersion] = ClassTag(classOf[ScalaVersion])
val OptionTag: ClassTag[Option[_]] = ClassTag(classOf[Option[_]])
val OptionTag: ClassTag[Option[?]] = ClassTag(classOf[Option[?]])
val OutputTag: ClassTag[AbstractFile] = ClassTag(classOf[AbstractFile])

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

private[this] var changed: Boolean = false

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

def isLegal(arg: Any): Boolean =
Expand All @@ -110,7 +110,7 @@ object Settings {
case x: Int => r.head <= x && x <= r.last
case _ => false
}
case xs: List[_] =>
case xs: List[?] =>
xs contains arg
}

Expand Down Expand Up @@ -193,12 +193,12 @@ object Settings {

class SettingGroup {

private[this] val _allSettings = new ArrayBuffer[Setting[_]]
def allSettings: Seq[Setting[_]] = _allSettings.toSeq
private[this] val _allSettings = new ArrayBuffer[Setting[?]]
def allSettings: Seq[Setting[?]] = _allSettings.toSeq

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

def userSetSettings(state: SettingsState): Seq[Setting[_]] =
def userSetSettings(state: SettingsState): Seq[Setting[?]] =
allSettings filterNot (_.isDefaultIn(state))

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

private def checkDependenciesOfSetting(state: ArgsSummary, setting: Setting[_]) =
private def checkDependenciesOfSetting(state: ArgsSummary, setting: Setting[?]) =
setting.depends.foldLeft(state) { (s, dep) =>
val (depSetting, reqValue) = dep
if (depSetting.valueIn(state.sstate) == reqValue) s
Expand Down Expand Up @@ -237,7 +237,7 @@ object Settings {
case "--" :: args =>
checkDependencies(stateWithArgs(skipped ++ args))
case x :: _ if x startsWith "-" =>
@tailrec def loop(settings: List[Setting[_]]): ArgsSummary = settings match {
@tailrec def loop(settings: List[Setting[?]]): ArgsSummary = settings match {
case setting :: settings1 =>
val state1 = setting.tryToSet(state)
if (state1 ne state) processArguments(state1, processAll, skipped)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ trait WrappedProperties extends PropertiesTrait {
def wrap[T](body: => T): Option[T]

protected def propCategory: String = "wrapped"
protected def pickJarBasedOn: Class[_] = this.getClass
protected def pickJarBasedOn: Class[?] = this.getClass

override def propIsSet(name: String): Boolean = wrap(super.propIsSet(name)) exists (x => x)
override def propOrElse(name: String, alt: String): String = wrap(super.propOrElse(name, alt)) getOrElse alt
Expand Down
18 changes: 9 additions & 9 deletions compiler/src/dotty/tools/dotc/core/Contexts.scala
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ object Contexts {
final def owner: Symbol = _owner

/** The current tree */
private[this] var _tree: Tree[_ >: Untyped]= _
protected def tree_=(tree: Tree[_ >: Untyped]): Unit = _tree = tree
final def tree: Tree[_ >: Untyped] = _tree
private[this] var _tree: Tree[? >: Untyped]= _
protected def tree_=(tree: Tree[? >: Untyped]): Unit = _tree = tree
final def tree: Tree[? >: Untyped] = _tree

/** The current scope */
private[this] var _scope: Scope = _
Expand Down Expand Up @@ -337,7 +337,7 @@ object Contexts {
* Note: Currently unused
def enclTemplate: Context = {
var c = this
while (c != NoContext && !c.tree.isInstanceOf[Template[_]] && !c.tree.isInstanceOf[PackageDef[_]])
while (c != NoContext && !c.tree.isInstanceOf[Template[?]] && !c.tree.isInstanceOf[PackageDef[?]])
c = c.outer
c
}*/
Expand Down Expand Up @@ -392,15 +392,15 @@ object Contexts {
}

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

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

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

def addLocation[T](initial: T): Store.Location[T] = {
Expand Down
12 changes: 6 additions & 6 deletions compiler/src/dotty/tools/dotc/core/Definitions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ class Definitions {
* Note that this will also extract the high bound if an
* element type is a wildcard. E.g.
*
* Array[_ <: Array[_ <: Number]]
* Array[? <: Array[? <: Number]]
*
* would match
*
Expand Down Expand Up @@ -1211,10 +1211,10 @@ class Definitions {
private val typeTags = mutable.Map[TypeName, Name]().withDefaultValue(nme.specializedTypeNames.Object)

// private val unboxedTypeRef = mutable.Map[TypeName, TypeRef]()
// private val javaTypeToValueTypeRef = mutable.Map[Class[_], TypeRef]()
// private val valueTypeNamesToJavaType = mutable.Map[TypeName, Class[_]]()
// private val javaTypeToValueTypeRef = mutable.Map[Class[?], TypeRef]()
// private val valueTypeNamesToJavaType = mutable.Map[TypeName, Class[?]]()

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

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

type PrimitiveClassEnc = Int
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ object Phases {
final def genBCodePhase: Phase = myGenBCodePhase

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

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