Skip to content

Commit

Permalink
Adapt the codebase to strict pattern binding warnings
Browse files Browse the repository at this point in the history
In order to bootstrap the compiler with the rules now enforced by default
by the previous commit.
  • Loading branch information
griggt committed Apr 16, 2022
1 parent 22ebd0c commit 869dfaa
Show file tree
Hide file tree
Showing 75 changed files with 151 additions and 150 deletions.
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/backend/jvm/BCodeBodyBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
// but I was able to derrive it by reading
// AbstractValidatingLambdaMetafactory.validateMetafactoryArgs

val DesugaredSelect(prefix, _) = fun
val DesugaredSelect(prefix, _) = fun: @unchecked
genLoad(prefix)
}

Expand Down Expand Up @@ -697,7 +697,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
lineNumber(app)
app match {
case Apply(_, args) if app.symbol eq defn.newArrayMethod =>
val List(elemClaz, Literal(c: Constant), ArrayValue(_, dims)) = args
val List(elemClaz, Literal(c: Constant), ArrayValue(_, dims)) = args: @unchecked

generatedType = toTypeKind(c.typeValue)
mkArrayConstructorCall(generatedType.asArrayBType, app, dims)
Expand Down Expand Up @@ -774,7 +774,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
if (invokeStyle.hasInstance) genLoadQualifier(fun)
genLoadArguments(args, paramTKs(app))

val DesugaredSelect(qual, name) = fun // fun is a Select, also checked in genLoadQualifier
val DesugaredSelect(qual, name) = fun: @unchecked // fun is a Select, also checked in genLoadQualifier
val isArrayClone = name == nme.clone_ && qual.tpe.widen.isInstanceOf[JavaArrayType]
if (isArrayClone) {
// Special-case Array.clone, introduced in 36ef60e. The goal is to generate this call
Expand Down Expand Up @@ -817,7 +817,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
} // end of genApply()

private def genArrayValue(av: tpd.JavaSeqLiteral): BType = {
val ArrayValue(tpt, elems) = av
val ArrayValue(tpt, elems) = av: @unchecked

lineNumber(av)
genArray(elems, tpt)
Expand Down Expand Up @@ -1492,7 +1492,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
import ScalaPrimitivesOps.{ ZNOT, ZAND, ZOR, EQ }

// lhs and rhs of test
lazy val DesugaredSelect(lhs, _) = fun
lazy val DesugaredSelect(lhs, _) = fun: @unchecked
val rhs = if (args.isEmpty) tpd.EmptyTree else args.head // args.isEmpty only for ZNOT

def genZandOrZor(and: Boolean): Unit = {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/jvm/BCodeHelpers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
// sorting ensures nested classes are listed after their enclosing class thus satisfying the Eclipse Java compiler
for (nestedClass <- allNestedClasses.sortBy(_.internalName.toString)) {
// Extract the innerClassEntry - we know it exists, enclosingNestedClassesChain only returns nested classes.
val Some(e) = nestedClass.innerClassAttributeEntry
val Some(e) = nestedClass.innerClassAttributeEntry: @unchecked
jclass.visitInnerClass(e.name, e.outerName, e.innerName, e.flags)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
val origSym = dd.symbol.asTerm
val newSym = makeStatifiedDefSymbol(origSym, origSym.name)
tpd.DefDef(newSym, { paramRefss =>
val selfParamRef :: regularParamRefs = paramRefss.head
val selfParamRef :: regularParamRefs = paramRefss.head: @unchecked
val enclosingClass = origSym.owner.asClass
new TreeTypeMap(
typeMap = _.substThis(enclosingClass, selfParamRef.symbol.termRef)
Expand Down
28 changes: 14 additions & 14 deletions compiler/src/dotty/tools/backend/sjs/JSCodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,7 @@ class JSCodeGen()(using genCtx: Context) {
*/

val (primaryTree :: Nil, secondaryTrees) =
constructorTrees.partition(_.symbol.isPrimaryConstructor)
constructorTrees.partition(_.symbol.isPrimaryConstructor): @unchecked

val primaryCtor = genPrimaryJSClassCtor(primaryTree)
val secondaryCtors = secondaryTrees.map(genSecondaryJSClassCtor(_))
Expand Down Expand Up @@ -1106,7 +1106,7 @@ class JSCodeGen()(using genCtx: Context) {

private def genPrimaryJSClassCtor(dd: DefDef): PrimaryJSCtor = {
val sym = dd.symbol
val Block(stats, _) = dd.rhs
val Block(stats, _) = dd.rhs: @unchecked
assert(sym.isPrimaryConstructor, s"called with non-primary ctor: $sym")

var jsSuperCall: Option[js.JSSuperConstructorCall] = None
Expand Down Expand Up @@ -1179,7 +1179,7 @@ class JSCodeGen()(using genCtx: Context) {

assert(thisCall.isDefined,
i"could not find the this() call in secondary JS constructor at ${dd.sourcePos}:\n${stats.map(_.show).mkString("\n")}")
val Some((targetCtor, ctorArgs)) = thisCall
val Some((targetCtor, ctorArgs)) = thisCall: @unchecked

new SplitSecondaryJSCtor(sym, genParamsAndInfo(sym, dd.paramss),
beforeThisCall.result(), targetCtor, ctorArgs, afterThisCall.result())
Expand Down Expand Up @@ -2139,7 +2139,7 @@ class JSCodeGen()(using genCtx: Context) {
*/
private def genSuperCall(tree: Apply, isStat: Boolean): js.Tree = {
implicit val pos = tree.span
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree: @unchecked
val sym = fun.symbol

if (sym == defn.Any_getClass) {
Expand Down Expand Up @@ -2180,7 +2180,7 @@ class JSCodeGen()(using genCtx: Context) {
private def genApplyNew(tree: Apply): js.Tree = {
implicit val pos: SourcePosition = tree.sourcePos

val Apply(fun @ Select(New(tpt), nme.CONSTRUCTOR), args) = tree
val Apply(fun @ Select(New(tpt), nme.CONSTRUCTOR), args) = tree: @unchecked
val ctor = fun.symbol
val tpe = tpt.tpe

Expand Down Expand Up @@ -2229,7 +2229,7 @@ class JSCodeGen()(using genCtx: Context) {
acquireContextualJSClassValue { jsClassValue =>
implicit val pos: Position = tree.span

val Apply(fun @ Select(New(tpt), _), args) = tree
val Apply(fun @ Select(New(tpt), _), args) = tree: @unchecked
val cls = tpt.tpe.typeSymbol
val ctor = fun.symbol

Expand Down Expand Up @@ -2898,7 +2898,7 @@ class JSCodeGen()(using genCtx: Context) {

implicit val pos = tree.span

val Apply(fun, args) = tree
val Apply(fun, args) = tree: @unchecked
val arrayObj = qualifierOf(fun)

val genArray = genExpr(arrayObj)
Expand Down Expand Up @@ -3167,7 +3167,7 @@ class JSCodeGen()(using genCtx: Context) {
private def genJSSuperCall(tree: Apply, isStat: Boolean): js.Tree = {
acquireContextualJSClassValue { explicitJSSuperClassValue =>
implicit val pos = tree.span
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree: @unchecked
val sym = fun.symbol

val genReceiver = genExpr(qual)
Expand Down Expand Up @@ -3242,7 +3242,7 @@ class JSCodeGen()(using genCtx: Context) {
/** Gen JS code for a switch-`Match`, which is translated into an IR `js.Match`. */
def genMatch(tree: Tree, isStat: Boolean): js.Tree = {
implicit val pos = tree.span
val Match(selector, cases) = tree
val Match(selector, cases) = tree: @unchecked

def abortMatch(msg: String): Nothing =
throw new FatalError(s"$msg in switch-like pattern match at ${tree.span}: $tree")
Expand Down Expand Up @@ -3441,7 +3441,7 @@ class JSCodeGen()(using genCtx: Context) {
val call = if (isStaticCall) {
genApplyStatic(sym, formalCaptures.map(_.ref) ::: actualParams)
} else {
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref): @unchecked
if (!sym.owner.isNonNativeJSClass || sym.isJSExposed)
genApplyMethodMaybeStatically(thisCaptureRef, sym, argCaptureRefs ::: actualParams)
else
Expand All @@ -3458,7 +3458,7 @@ class JSCodeGen()(using genCtx: Context) {
}

if (isThisFunction) {
val thisParam :: otherParams = formalParams
val thisParam :: otherParams = formalParams: @unchecked
js.Closure(
arrow = false,
formalCaptures,
Expand Down Expand Up @@ -3970,7 +3970,7 @@ class JSCodeGen()(using genCtx: Context) {
*/
private def genReflectiveCall(tree: Apply, isSelectDynamic: Boolean): js.Tree = {
implicit val pos = tree.span
val Apply(fun @ Select(receiver, _), args) = tree
val Apply(fun @ Select(receiver, _), args) = tree: @unchecked

val selectedValueTree = js.Apply(js.ApplyFlags.empty, genExpr(receiver),
js.MethodIdent(selectedValueMethodName), Nil)(jstpe.AnyType)
Expand Down Expand Up @@ -4213,7 +4213,7 @@ class JSCodeGen()(using genCtx: Context) {
private def genCaptureValuesFromFakeNewInstance(tree: Tree): List[js.Tree] = {
implicit val pos: Position = tree.span

val Apply(fun @ Select(New(_), _), args) = tree
val Apply(fun @ Select(New(_), _), args) = tree: @unchecked
val sym = fun.symbol

/* We use the same strategy as genActualJSArgs to detect which parameters were
Expand Down Expand Up @@ -4539,7 +4539,7 @@ class JSCodeGen()(using genCtx: Context) {
pathName.split('.').toList

def parseGlobalPath(pathName: String): Global = {
val globalRef :: path = parsePath(pathName)
val globalRef :: path = parsePath(pathName): @unchecked
Global(globalRef, path)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/backend/sjs/JSExportsGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
None
} else {
val formalArgsRegistry = new FormalArgsRegistry(1, false)
val (List(arg), None) = formalArgsRegistry.genFormalArgs()
val (List(arg), None) = formalArgsRegistry.genFormalArgs(): @unchecked
val body = genOverloadDispatchSameArgc(jsName, formalArgsRegistry,
setters.map(new ExportedSymbol(_, static)), jstpe.AnyType, None)
Some((arg, body))
Expand Down
8 changes: 4 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/Desugar.scala
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ object desugar {

/** The expansion of a class definition. See inline comments for what is involved */
def classDef(cdef: TypeDef)(using Context): Tree = {
val impl @ Template(constr0, _, self, _) = cdef.rhs
val impl @ Template(constr0, _, self, _) = cdef.rhs: @unchecked
val className = normalizeName(cdef, impl).asTypeName
val parents = impl.parents
val mods = cdef.mods
Expand Down Expand Up @@ -682,7 +682,7 @@ object desugar {
.withMods(companionMods | Synthetic))
.withSpan(cdef.span).toList
if (companionDerived.nonEmpty)
for (modClsDef @ TypeDef(_, _) <- mdefs)
for (case modClsDef @ TypeDef(_, _) <- mdefs)
modClsDef.putAttachment(DerivingCompanion, impl.srcPos.startPos)
mdefs
}
Expand Down Expand Up @@ -740,7 +740,7 @@ object desugar {

enumCompanionRef match {
case ref: TermRefTree => // have the enum import watch the companion object
val (modVal: ValDef) :: _ = companions
val (modVal: ValDef) :: _ = companions: @unchecked
ref.watching(modVal)
case _ =>
}
Expand Down Expand Up @@ -1200,7 +1200,7 @@ object desugar {

/** Expand variable identifier x to x @ _ */
def patternVar(tree: Tree)(using Context): Bind = {
val Ident(name) = unsplice(tree)
val Ident(name) = unsplice(tree): @unchecked
Bind(name, Ident(nme.WILDCARD)).withSpan(tree.span)
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/MainProxies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ object MainProxies {
case TypeDef(_, template: Template) =>
template.body.flatMap((_: Tree) match {
case dd: DefDef if dd.name.is(DefaultGetterName) && dd.name.firstPart == funSymbol.name =>
val DefaultGetterName.NumberedInfo(index) = dd.name.info
val DefaultGetterName.NumberedInfo(index) = dd.name.info: @unchecked
List(index -> dd.symbol)
case _ => Nil
}).toMap
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeInfo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -952,7 +952,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
Some(tree.args.head)
else if tree.symbol == defn.QuotedTypeModule_of then
// quoted.Type.of[<body>](quotes)
val TypeApply(_, body :: _) = tree.fun
val TypeApply(_, body :: _) = tree.fun: @unchecked
Some(body)
else None
}
Expand Down
3 changes: 2 additions & 1 deletion compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala
Original file line number Diff line number Diff line change
Expand Up @@ -153,9 +153,10 @@ class TreeTypeMap(

private def transformAllParamss(paramss: List[ParamClause]): (TreeTypeMap, List[ParamClause]) = paramss match
case params :: paramss1 =>
val (tmap1, params1: ParamClause) = (params: @unchecked) match
val (tmap1, params1: ParamClause) = ((params: @unchecked) match
case ValDefs(vparams) => transformDefs(vparams)
case TypeDefs(tparams) => transformDefs(tparams)
): @unchecked
val (tmap2, paramss2) = tmap1.transformAllParamss(paramss1)
(tmap2, params1 :: paramss2)
case nil =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
ta.assignType(untpd.TypeDef(sym.name, TypeTree(sym.info)), sym)

def ClassDef(cls: ClassSymbol, constr: DefDef, body: List[Tree], superArgs: List[Tree] = Nil)(using Context): TypeDef = {
val firstParent :: otherParents = cls.info.parents
val firstParent :: otherParents = cls.info.parents: @unchecked
val superRef =
if (cls.is(Trait)) TypeTree(firstParent)
else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/config/Settings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ object Settings:
}

def tryToSet(state: ArgsSummary): ArgsSummary = {
val ArgsSummary(sstate, arg :: args, errors, warnings) = state
val ArgsSummary(sstate, arg :: args, errors, warnings) = state: @unchecked
def update(value: Any, args: List[String]): ArgsSummary =
var dangers = warnings
val value1 =
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/Annotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ object Annotations {
if (i < args.length) Some(args(i)) else None
}
def argumentConstant(i: Int)(using Context): Option[Constant] =
for (ConstantType(c) <- argument(i) map (_.tpe.widenTermRefExpr.normalized)) yield c
for (case ConstantType(c) <- argument(i) map (_.tpe.widenTermRefExpr.normalized)) yield c

def argumentConstantString(i: Int)(using Context): Option[String] =
for (Constant(s: String) <- argumentConstant(i)) yield s
for (case Constant(s: String) <- argumentConstant(i)) yield s

/** The tree evaluaton is in progress. */
def isEvaluating: Boolean = false
Expand Down Expand Up @@ -219,7 +219,7 @@ object Annotations {

def unapply(ann: Annotation)(using Context): Option[Symbol] =
if (ann.symbol == defn.ChildAnnot) {
val AppliedType(_, (arg: NamedType) :: Nil) = ann.tree.tpe
val AppliedType(_, (arg: NamedType) :: Nil) = ann.tree.tpe: @unchecked
Some(arg.symbol)
}
else None
Expand Down
6 changes: 3 additions & 3 deletions compiler/src/dotty/tools/dotc/core/ConstraintHandling.scala
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ trait ConstraintHandling {
(c1 eq constraint)
|| {
constraint = c1
val TypeBounds(lo, hi) = constraint.entry(param)
val TypeBounds(lo, hi) = constraint.entry(param): @unchecked
isSub(lo, hi)
}
end addOneBound
Expand Down Expand Up @@ -362,7 +362,7 @@ trait ConstraintHandling {

if level1 != level2 then
boundRemoved = LevelAvoidMap(-1, math.min(level1, level2))(boundRemoved)
val TypeBounds(lo, hi) = boundRemoved
val TypeBounds(lo, hi) = boundRemoved: @unchecked
// After avoidance, the interval might be empty, e.g. in
// tests/pos/i8900-promote.scala:
// >: x.type <: Singleton
Expand Down Expand Up @@ -410,7 +410,7 @@ trait ConstraintHandling {
*/
protected final def isSatisfiable(using Context): Boolean =
constraint.forallParams { param =>
val TypeBounds(lo, hi) = constraint.entry(param)
val TypeBounds(lo, hi) = constraint.entry(param): @unchecked
isSub(lo, hi) || {
report.log(i"sub fail $lo <:< $hi")
false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,
if (tl.isInstanceOf[HKLambda]) {
// HKLambdas are hash-consed, need to create an artificial difference by adding
// a LazyRef to a bound.
val TypeBounds(lo, hi) :: pinfos1 = tl.paramInfos
val TypeBounds(lo, hi) :: pinfos1 = tl.paramInfos: @unchecked
paramInfos = TypeBounds(lo, LazyRef.of(hi)) :: pinfos1
}
ensureFresh(tl.newLikeThis(tl.paramNames, paramInfos, tl.resultType))
Expand Down
10 changes: 5 additions & 5 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2150,8 +2150,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
def lubArgs(args1: List[Type], args2: List[Type], tparams: List[TypeParamInfo], canConstrain: Boolean = false): List[Type] =
tparams match {
case tparam :: tparamsRest =>
val arg1 :: args1Rest = args1
val arg2 :: args2Rest = args2
val arg1 :: args1Rest = args1: @unchecked
val arg2 :: args2Rest = args2: @unchecked
val common = singletonInterval(arg1, arg2)
val v = tparam.paramVarianceSign
val lubArg =
Expand Down Expand Up @@ -2182,8 +2182,8 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
def glbArgs(args1: List[Type], args2: List[Type], tparams: List[TypeParamInfo]): List[Type] =
tparams match {
case tparam :: tparamsRest =>
val arg1 :: args1Rest = args1
val arg2 :: args2Rest = args2
val arg1 :: args1Rest = args1: @unchecked
val arg2 :: args2Rest = args2: @unchecked
val common = singletonInterval(arg1, arg2)
val v = tparam.paramVarianceSign
val glbArg =
Expand Down Expand Up @@ -2921,7 +2921,7 @@ class TrackingTypeComparer(initctx: Context) extends TypeComparer(initctx) {
cas
}

val defn.MatchCase(pat, body) = cas1
val defn.MatchCase(pat, body) = cas1: @unchecked

if (isSubType(scrut, pat))
// `scrut` is a subtype of `pat`: *It's a Match!*
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ class TypeErasure(sourceLanguage: SourceLanguage, semiEraseVCs: Boolean, isConst
}

private def eraseArray(tp: Type)(using Context) = {
val defn.ArrayOf(elemtp) = tp
val defn.ArrayOf(elemtp) = tp: @unchecked
if (isGenericArrayElement(elemtp, isScala2 = sourceLanguage.isScala2)) defn.ObjectType
else
try JavaArrayType(erasureFn(sourceLanguage, semiEraseVCs = false, isConstructor, isSymbol, wildcardOK)(elemtp))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ class ClassfileParser(
*/
def normalizeConstructorParams() = innerClasses.get(currentClassName.toString) match {
case Some(entry) if !isStatic(entry.jflags) =>
val mt @ MethodTpe(paramNames, paramTypes, resultType) = denot.info
val mt @ MethodTpe(paramNames, paramTypes, resultType) = denot.info: @unchecked
var normalizedParamNames = paramNames.tail
var normalizedParamTypes = paramTypes.tail
if ((jflags & JAVA_ACC_SYNTHETIC) != 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class TastyPickler(val rootCls: ClassSymbol) {
sections.foreach(_._2.assemble())

val nameBufferHash = TastyHash.pjwHash64(nameBuffer.bytes)
val treeSectionHash +: otherSectionHashes = sections.map(x => TastyHash.pjwHash64(x._2.bytes))
val treeSectionHash +: otherSectionHashes = sections.map(x => TastyHash.pjwHash64(x._2.bytes)): @unchecked

val tastyVersion = ctx.tastyVersion

Expand Down
Loading

0 comments on commit 869dfaa

Please sign in to comment.