Skip to content

Commit

Permalink
Disallow _ for wildcard arguments of types and use ?
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Nov 1, 2023
1 parent 699ed87 commit a801c15
Show file tree
Hide file tree
Showing 455 changed files with 1,205 additions and 1,192 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class ClassfileWriters(frontendAccess: PostProcessorFrontendAccess) {

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

private def checkName(component: Path): Unit = if (isWindows) {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/CoreBTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ abstract class CoreBTypesFromSymbols[I <: DottyBackendInterface] extends CoreBTy
lazy val jlStringBuilderRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.lang.StringBuilder])
lazy val jlStringBufferRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.lang.StringBuffer])
lazy val jlCharSequenceRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.lang.CharSequence])
lazy val jlClassRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.lang.Class[_]])
lazy val jlClassRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.lang.Class[?]])
lazy val jlThrowableRef : ClassBType = synchClassBTypeFromSymbol(defn.ThrowableClass)
lazy val jlCloneableRef : ClassBType = synchClassBTypeFromSymbol(defn.JavaCloneableClass)
lazy val jiSerializableRef : ClassBType = synchClassBTypeFromSymbol(requiredClass[java.io.Serializable])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ class DottyBackendInterface(val superCallsMap: ReadOnlyMap[Symbol, Set[ClassSymb

object DottyBackendInterface {

private def erasureString(clazz: Class[_]): String = {
private def erasureString(clazz: Class[?]): String = {
if (clazz.isArray) "Array[" + erasureString(clazz.getComponentType) + "]"
else clazz.getName
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ abstract class NestedClassesCollector[T](nestedOnly: Boolean) extends GenericSig
if (annot.values != null) annot.values.asScala foreach visitConstant
}

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

def visitHandle(handle: Handle): Unit = {
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1089,7 +1089,7 @@ class JSCodeGen()(using genCtx: Context) {
val exports = List.newBuilder[jsExportsGen.Exported]
val jsClassCaptures = List.newBuilder[js.ParamDef]

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

case body =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/ScopedVar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ object ScopedVar {

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

def withScopedVars[T](ass: Assignment[_]*)(body: => T): T = {
def withScopedVars[T](ass: Assignment[?]*)(body: => T): T = {
val stack = ass.map(_.push())
try body
finally stack.reverse.foreach(_.pop())
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ trait TreeInfo[T <: Untyped] { self: Trees.Instance[T] =>

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

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

def assertAllPositioned(tree: Tree)(using Context): Unit =
tree.foreachSubTree {
case t: WithoutTypeOrPos[_] =>
case t: WithoutTypeOrPos[?] =>
case t => assert(t.span.exists, i"$t")
}

Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ object Trees {

/** Property key for backquoted identifiers and definitions */
val Backquoted: Property.StickyKey[Unit] = Property.StickyKey()

val SyntheticUnit: Property.StickyKey[Unit] = Property.StickyKey()

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

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

def trailingParamss(using Context): List[ParamClause[T]] = paramss match
case ((tparam: TypeDef[_]) :: _) :: paramss1 => paramss1
case ((tparam: TypeDef[?]) :: _) :: paramss1 => paramss1
case _ => paramss

def termParamss(using Context): List[List[ValDef[T]]] =
Expand Down
1 change: 1 addition & 0 deletions compiler/src/dotty/tools/dotc/config/Feature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ object Feature:
val dependent = experimental("dependent")
val erasedDefinitions = experimental("erasedDefinitions")
val symbolLiterals = deprecated("symbolLiterals")
val underscoreWildcards = deprecated("underscoreWildcards")
val fewerBraces = experimental("fewerBraces")
val saferExceptions = experimental("saferExceptions")
val clauseInterleaving = experimental("clauseInterleaving")
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -649,13 +649,13 @@ class Inliner(val call: tpd.Tree)(using Context):
def treeSize(x: Any): Int =
var siz = 0
x match
case x: Trees.Inlined[_] =>
case x: Trees.Inlined[?] =>
case x: Positioned =>
var i = 0
while i < x.productArity do
siz += treeSize(x.productElement(i))
i += 1
case x: List[_] =>
case x: List[?] =>
var xs = x
while xs.nonEmpty do
siz += treeSize(xs.head)
Expand Down
9 changes: 6 additions & 3 deletions compiler/src/dotty/tools/dotc/parsing/Parsers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1856,9 +1856,12 @@ object Parsers {
val start = in.skipToken()
Ident(tpnme.USCOREkw).withSpan(Span(start, in.lastOffset, start))
else
if sourceVersion.isAtLeast(future) then
deprecationWarning(em"`_` is deprecated for wildcard arguments of types: use `?` instead")
patch(source, Span(in.offset, in.offset + 1), "?")
if !in.featureEnabled(Feature.underscoreWildcards) then
report.errorOrMigrationWarning(
em"`_` is deprecated for wildcard arguments of types: use `?` instead${rewriteNotice(`3.4-migration`)}",
in.sourcePos(), from = `3.4`)
if sourceVersion == `3.4-migration` then
patch(source, Span(in.offset, in.offset + 1), "?")
val start = in.skipToken()
typeBounds().withSpan(Span(start, in.lastOffset, start))
// Allow symbols -_ and +_ through for compatibility with code written using kind-projector in Scala 3 underscore mode.
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
core ~ cs.optionalInfo

private def toTextRetainedElem[T <: Untyped](ref: Tree[T]): Text = ref match
case ref: RefTree[_] if ref.typeOpt.exists =>
case ref: RefTree[?] if ref.typeOpt.exists =>
toTextCaptureRef(ref.typeOpt)
case Apply(fn, Literal(str) :: Nil) if fn.symbol == defn.Caps_capIn =>
s"cap[${str.stringValue}]"
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/reporting/messages.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2648,7 +2648,7 @@ class ExtensionCanOnlyHaveDefs(mdef: untpd.Tree)(using Context)
|"""
}

class UnexpectedPatternForSummonFrom(tree: Tree[_])(using Context)
class UnexpectedPatternForSummonFrom(tree: Tree[?])(using Context)
extends SyntaxMsg(UnexpectedPatternForSummonFromID) {
def msg(using Context) = i"Unexpected pattern for summonFrom. Expected ${hl("`x: T`")} or ${hl("`_`")}"
def explain(using Context) =
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/util/Stats.scala
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import collection.mutable
hits(name) += n
}

def doRecordSize(fn: String, coll: scala.collection.Iterable[_]): coll.type =
def doRecordSize(fn: String, coll: scala.collection.Iterable[?]): coll.type =
doRecord(fn, coll.size)
coll

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler

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

def seal: scala.quoted.Type[_] = self.asType
def seal: scala.quoted.Type[?] = self.asType

def asType: scala.quoted.Type[?] =
new TypeImpl(Inferred(self), SpliceScope.getCurrent)
Expand Down
2 changes: 1 addition & 1 deletion compiler/test/dotty/tools/backend/jvm/AsmNode.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ sealed trait AsmNode[+T] {
object AsmNode {
type AsmMethod = AsmNode[MethodNode]
type AsmField = AsmNode[FieldNode]
type AsmMember = AsmNode[_]
type AsmMember = AsmNode[?]

implicit class ClassNodeOps(val node: ClassNode) {
def fieldsAndMethods: List[AsmMember] = {
Expand Down
6 changes: 3 additions & 3 deletions compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ trait DottyBytecodeTest {
assert(succ, msg)
}

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

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

protected def boxingInstructions(method: MethodNode): (List[_], Boolean) = {
protected def boxingInstructions(method: MethodNode): (List[?], Boolean) = {
val ins = instructionsFromMethod(method)
val boxed = ins.exists {
case Invoke(op, owner, name, desc, itf) =>
Expand Down
Loading

0 comments on commit a801c15

Please sign in to comment.