Skip to content

Commit 46329ee

Browse files
committed
Adapt the codebase to strict pattern binding warnings
In order to bootstrap the compiler with the rules now enforced by default by the previous commit.
1 parent 0bddf1b commit 46329ee

File tree

76 files changed

+156
-155
lines changed

Some content is hidden

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

76 files changed

+156
-155
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
359359
// but I was able to derrive it by reading
360360
// AbstractValidatingLambdaMetafactory.validateMetafactoryArgs
361361

362-
val DesugaredSelect(prefix, _) = fun
362+
val DesugaredSelect(prefix, _) = fun: @unchecked
363363
genLoad(prefix)
364364
}
365365

@@ -725,7 +725,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
725725
lineNumber(app)
726726
app match {
727727
case Apply(_, args) if app.symbol eq defn.newArrayMethod =>
728-
val List(elemClaz, Literal(c: Constant), ArrayValue(_, dims)) = args
728+
val List(elemClaz, Literal(c: Constant), ArrayValue(_, dims)) = args: @unchecked
729729

730730
generatedType = toTypeKind(c.typeValue)
731731
mkArrayConstructorCall(generatedType.asArrayBType, app, dims)
@@ -802,7 +802,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
802802
if (invokeStyle.hasInstance) genLoadQualifier(fun)
803803
genLoadArguments(args, paramTKs(app))
804804

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

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

850850
lineNumber(av)
851851
genArray(elems, tpt)
@@ -1530,7 +1530,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
15301530
import ScalaPrimitivesOps.{ ZNOT, ZAND, ZOR, EQ }
15311531

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

15361536
def genZandOrZor(and: Boolean): Unit = {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
151151
// sorting ensures nested classes are listed after their enclosing class thus satisfying the Eclipse Java compiler
152152
for (nestedClass <- allNestedClasses.sortBy(_.internalName.toString)) {
153153
// Extract the innerClassEntry - we know it exists, enclosingNestedClassesChain only returns nested classes.
154-
val Some(e) = nestedClass.innerClassAttributeEntry
154+
val Some(e) = nestedClass.innerClassAttributeEntry: @unchecked
155155
jclass.visitInnerClass(e.name, e.outerName, e.innerName, e.flags)
156156
}
157157
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
689689
val origSym = dd.symbol.asTerm
690690
val newSym = makeStatifiedDefSymbol(origSym, origSym.name)
691691
tpd.DefDef(newSym, { paramRefss =>
692-
val selfParamRef :: regularParamRefs = paramRefss.head
692+
val selfParamRef :: regularParamRefs = paramRefss.head: @unchecked
693693
val enclosingClass = origSym.owner.asClass
694694
new TreeTypeMap(
695695
typeMap = _.substThis(enclosingClass, selfParamRef.symbol.termRef)

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

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ class JSCodeGen()(using genCtx: Context) {
10251025
*/
10261026

10271027
val (primaryTree :: Nil, secondaryTrees) =
1028-
constructorTrees.partition(_.symbol.isPrimaryConstructor)
1028+
constructorTrees.partition(_.symbol.isPrimaryConstructor): @unchecked
10291029

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

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

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

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

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

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

2183-
val Apply(fun @ Select(New(tpt), nme.CONSTRUCTOR), args) = tree
2183+
val Apply(fun @ Select(New(tpt), nme.CONSTRUCTOR), args) = tree: @unchecked
21842184
val ctor = fun.symbol
21852185
val tpe = tpt.tpe
21862186

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

2232-
val Apply(fun @ Select(New(tpt), _), args) = tree
2232+
val Apply(fun @ Select(New(tpt), _), args) = tree: @unchecked
22332233
val cls = tpt.tpe.typeSymbol
22342234
val ctor = fun.symbol
22352235

@@ -2898,7 +2898,7 @@ class JSCodeGen()(using genCtx: Context) {
28982898

28992899
implicit val pos = tree.span
29002900

2901-
val Apply(fun, args) = tree
2901+
val Apply(fun, args) = tree: @unchecked
29022902
val arrayObj = qualifierOf(fun)
29032903

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

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

32473247
def abortMatch(msg: String): Nothing =
32483248
throw new FatalError(s"$msg in switch-like pattern match at ${tree.span}: $tree")
@@ -3441,7 +3441,7 @@ class JSCodeGen()(using genCtx: Context) {
34413441
val call = if (isStaticCall) {
34423442
genApplyStatic(sym, formalCaptures.map(_.ref) ::: actualParams)
34433443
} else {
3444-
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
3444+
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref): @unchecked
34453445
if (!sym.owner.isNonNativeJSClass || sym.isJSExposed)
34463446
genApplyMethodMaybeStatically(thisCaptureRef, sym, argCaptureRefs ::: actualParams)
34473447
else
@@ -3458,7 +3458,7 @@ class JSCodeGen()(using genCtx: Context) {
34583458
}
34593459

34603460
if (isThisFunction) {
3461-
val thisParam :: otherParams = formalParams
3461+
val thisParam :: otherParams = formalParams: @unchecked
34623462
js.Closure(
34633463
arrow = false,
34643464
formalCaptures,
@@ -3970,7 +3970,7 @@ class JSCodeGen()(using genCtx: Context) {
39703970
*/
39713971
private def genReflectiveCall(tree: Apply, isSelectDynamic: Boolean): js.Tree = {
39723972
implicit val pos = tree.span
3973-
val Apply(fun @ Select(receiver, _), args) = tree
3973+
val Apply(fun @ Select(receiver, _), args) = tree: @unchecked
39743974

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

4216-
val Apply(fun @ Select(New(_), _), args) = tree
4216+
val Apply(fun @ Select(New(_), _), args) = tree: @unchecked
42174217
val sym = fun.symbol
42184218

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

45414541
def parseGlobalPath(pathName: String): Global = {
4542-
val globalRef :: path = parsePath(pathName)
4542+
val globalRef :: path = parsePath(pathName): @unchecked
45434543
Global(globalRef, path)
45444544
}
45454545

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
356356
None
357357
} else {
358358
val formalArgsRegistry = new FormalArgsRegistry(1, false)
359-
val (List(arg), None) = formalArgsRegistry.genFormalArgs()
359+
val (List(arg), None) = formalArgsRegistry.genFormalArgs(): @unchecked
360360
val body = genOverloadDispatchSameArgc(jsName, formalArgsRegistry,
361361
setters.map(new ExportedSymbol(_, static)), jstpe.AnyType, None)
362362
Some((arg, body))

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ object desugar {
405405

406406
/** The expansion of a class definition. See inline comments for what is involved */
407407
def classDef(cdef: TypeDef)(using Context): Tree = {
408-
val impl @ Template(constr0, _, self, _) = cdef.rhs
408+
val impl @ Template(constr0, _, self, _) = cdef.rhs: @unchecked
409409
val className = normalizeName(cdef, impl).asTypeName
410410
val parents = impl.parents
411411
val mods = cdef.mods
@@ -695,7 +695,7 @@ object desugar {
695695
.withMods(companionMods | Synthetic))
696696
.withSpan(cdef.span).toList
697697
if (companionDerived.nonEmpty)
698-
for (modClsDef @ TypeDef(_, _) <- mdefs)
698+
for (case modClsDef @ TypeDef(_, _) <- mdefs)
699699
modClsDef.putAttachment(DerivingCompanion, impl.srcPos.startPos)
700700
mdefs
701701
}
@@ -753,7 +753,7 @@ object desugar {
753753

754754
enumCompanionRef match {
755755
case ref: TermRefTree => // have the enum import watch the companion object
756-
val (modVal: ValDef) :: _ = companions
756+
val (modVal: ValDef) :: _ = companions: @unchecked
757757
ref.watching(modVal)
758758
case _ =>
759759
}
@@ -1215,7 +1215,7 @@ object desugar {
12151215

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ object MainProxies {
183183
case TypeDef(_, template: Template) =>
184184
template.body.flatMap((_: Tree) match {
185185
case dd: DefDef if dd.name.is(DefaultGetterName) && dd.name.firstPart == funSymbol.name =>
186-
val DefaultGetterName.NumberedInfo(index) = dd.name.info
186+
val DefaultGetterName.NumberedInfo(index) = dd.name.info: @unchecked
187187
List(index -> dd.symbol)
188188
case _ => Nil
189189
}).toMap

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
956956
Some(tree.args.head)
957957
else if tree.symbol == defn.QuotedTypeModule_of then
958958
// quoted.Type.of[<body>](quotes)
959-
val TypeApply(_, body :: _) = tree.fun
959+
val TypeApply(_, body :: _) = tree.fun: @unchecked
960960
Some(body)
961961
else None
962962
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,9 +156,10 @@ class TreeTypeMap(
156156

157157
private def transformAllParamss(paramss: List[ParamClause]): (TreeTypeMap, List[ParamClause]) = paramss match
158158
case params :: paramss1 =>
159-
val (tmap1, params1: ParamClause) = (params: @unchecked) match
159+
val (tmap1, params1: ParamClause) = ((params: @unchecked) match
160160
case ValDefs(vparams) => transformDefs(vparams)
161161
case TypeDefs(tparams) => transformDefs(tparams)
162+
): @unchecked
162163
val (tmap2, paramss2) = tmap1.transformAllParamss(paramss1)
163164
(tmap2, params1 :: paramss2)
164165
case nil =>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -293,7 +293,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
293293
ta.assignType(untpd.TypeDef(sym.name, TypeTree(sym.info)), sym)
294294

295295
def ClassDef(cls: ClassSymbol, constr: DefDef, body: List[Tree], superArgs: List[Tree] = Nil)(using Context): TypeDef = {
296-
val firstParent :: otherParents = cls.info.parents
296+
val firstParent :: otherParents = cls.info.parents: @unchecked
297297
val superRef =
298298
if (cls.is(Trait)) TypeTree(firstParent)
299299
else {

0 commit comments

Comments
 (0)