Skip to content

Commit 6adab71

Browse files
committed
Adapt the codebase to stricter pattern binding rules
In order to bootstrap the compiler with the rules now enforced by default by the previous commit.
1 parent 91f70cf commit 6adab71

File tree

73 files changed

+149
-148
lines changed

Some content is hidden

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

73 files changed

+149
-148
lines changed

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

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

353-
val DesugaredSelect(prefix, _) = fun
353+
val DesugaredSelect(prefix, _) = fun: @unchecked
354354
genLoad(prefix)
355355
}
356356

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

699699
generatedType = toTypeKind(c.typeValue)
700700
mkArrayConstructorCall(generatedType.asArrayBType, app, dims)
@@ -771,7 +771,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
771771
if (invokeStyle.hasInstance) genLoadQualifier(fun)
772772
genLoadArguments(args, paramTKs(app))
773773

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

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

819819
lineNumber(av)
820820
genArray(elems, tpt)
@@ -1490,7 +1490,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
14901490
import ScalaPrimitivesOps.{ ZNOT, ZAND, ZOR, EQ }
14911491

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

14961496
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
@@ -150,7 +150,7 @@ trait BCodeHelpers extends BCodeIdiomatic with BytecodeWriters {
150150
// sorting ensures nested classes are listed after their enclosing class thus satisfying the Eclipse Java compiler
151151
for (nestedClass <- allNestedClasses.sortBy(_.internalName.toString)) {
152152
// Extract the innerClassEntry - we know it exists, enclosingNestedClassesChain only returns nested classes.
153-
val Some(e) = nestedClass.innerClassAttributeEntry
153+
val Some(e) = nestedClass.innerClassAttributeEntry: @unchecked
154154
jclass.visitInnerClass(e.name, e.outerName, e.innerName, e.flags)
155155
}
156156
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
670670
val origSym = dd.symbol.asTerm
671671
val newSym = makeStatifiedDefSymbol(origSym, origSym.name)
672672
tpd.DefDef(newSym, { paramRefss =>
673-
val selfParamRef :: regularParamRefs = paramRefss.head
673+
val selfParamRef :: regularParamRefs = paramRefss.head: @unchecked
674674
val enclosingClass = origSym.owner.asClass
675675
new TreeTypeMap(
676676
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
@@ -1032,7 +1032,7 @@ class JSCodeGen()(using genCtx: Context) {
10321032
*/
10331033

10341034
val (primaryTree :: Nil, secondaryTrees) =
1035-
constructorTrees.partition(_.symbol.isPrimaryConstructor)
1035+
constructorTrees.partition(_.symbol.isPrimaryConstructor): @unchecked
10361036

10371037
val primaryCtor = genPrimaryJSClassCtor(primaryTree)
10381038
val secondaryCtors = secondaryTrees.map(genSecondaryJSClassCtor(_))
@@ -1113,7 +1113,7 @@ class JSCodeGen()(using genCtx: Context) {
11131113

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

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

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

11911191
new SplitSecondaryJSCtor(sym, genParamsAndInfo(sym, dd.paramss),
11921192
beforeThisCall.result(), targetCtor, ctorArgs, afterThisCall.result())
@@ -2151,7 +2151,7 @@ class JSCodeGen()(using genCtx: Context) {
21512151
*/
21522152
private def genSuperCall(tree: Apply, isStat: Boolean): js.Tree = {
21532153
implicit val pos = tree.span
2154-
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree
2154+
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree: @unchecked
21552155
val sym = fun.symbol
21562156

21572157
if (sym == defn.Any_getClass) {
@@ -2192,7 +2192,7 @@ class JSCodeGen()(using genCtx: Context) {
21922192
private def genApplyNew(tree: Apply): js.Tree = {
21932193
implicit val pos: SourcePosition = tree.sourcePos
21942194

2195-
val Apply(fun @ Select(New(tpt), nme.CONSTRUCTOR), args) = tree
2195+
val Apply(fun @ Select(New(tpt), nme.CONSTRUCTOR), args) = tree: @unchecked
21962196
val ctor = fun.symbol
21972197
val tpe = tpt.tpe
21982198

@@ -2241,7 +2241,7 @@ class JSCodeGen()(using genCtx: Context) {
22412241
acquireContextualJSClassValue { jsClassValue =>
22422242
implicit val pos: Position = tree.span
22432243

2244-
val Apply(fun @ Select(New(tpt), _), args) = tree
2244+
val Apply(fun @ Select(New(tpt), _), args) = tree: @unchecked
22452245
val cls = tpt.tpe.typeSymbol
22462246
val ctor = fun.symbol
22472247

@@ -2911,7 +2911,7 @@ class JSCodeGen()(using genCtx: Context) {
29112911

29122912
implicit val pos = tree.span
29132913

2914-
val Apply(fun, args) = tree
2914+
val Apply(fun, args) = tree: @unchecked
29152915
val arrayObj = qualifierOf(fun)
29162916

29172917
val genArray = genExpr(arrayObj)
@@ -3180,7 +3180,7 @@ class JSCodeGen()(using genCtx: Context) {
31803180
private def genJSSuperCall(tree: Apply, isStat: Boolean): js.Tree = {
31813181
acquireContextualJSClassValue { explicitJSSuperClassValue =>
31823182
implicit val pos = tree.span
3183-
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree
3183+
val Apply(fun @ Select(sup @ Super(qual, _), _), args) = tree: @unchecked
31843184
val sym = fun.symbol
31853185

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

32603260
def abortMatch(msg: String): Nothing =
32613261
throw new FatalError(s"$msg in switch-like pattern match at ${tree.span}: $tree")
@@ -3454,7 +3454,7 @@ class JSCodeGen()(using genCtx: Context) {
34543454
val call = if (isStaticCall) {
34553455
genApplyStatic(sym, formalCaptures.map(_.ref) ::: actualParams)
34563456
} else {
3457-
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref)
3457+
val thisCaptureRef :: argCaptureRefs = formalCaptures.map(_.ref): @unchecked
34583458
if (!sym.owner.isNonNativeJSClass || sym.isJSExposed)
34593459
genApplyMethodMaybeStatically(thisCaptureRef, sym, argCaptureRefs ::: actualParams)
34603460
else
@@ -3471,7 +3471,7 @@ class JSCodeGen()(using genCtx: Context) {
34713471
}
34723472

34733473
if (isThisFunction) {
3474-
val thisParam :: otherParams = formalParams
3474+
val thisParam :: otherParams = formalParams: @unchecked
34753475
js.Closure(
34763476
arrow = false,
34773477
formalCaptures,
@@ -3983,7 +3983,7 @@ class JSCodeGen()(using genCtx: Context) {
39833983
*/
39843984
private def genReflectiveCall(tree: Apply, isSelectDynamic: Boolean): js.Tree = {
39853985
implicit val pos = tree.span
3986-
val Apply(fun @ Select(receiver, _), args) = tree
3986+
val Apply(fun @ Select(receiver, _), args) = tree: @unchecked
39873987

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

4229-
val Apply(fun @ Select(New(_), _), args) = tree
4229+
val Apply(fun @ Select(New(_), _), args) = tree: @unchecked
42304230
val sym = fun.symbol
42314231

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

45544554
def parseGlobalPath(pathName: String): Global = {
4555-
val globalRef :: path = parsePath(pathName)
4555+
val globalRef :: path = parsePath(pathName): @unchecked
45564556
Global(globalRef, path)
45574557
}
45584558

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ final class JSExportsGen(jsCodeGen: JSCodeGen)(using Context) {
363363
None
364364
} else {
365365
val formalArgsRegistry = new FormalArgsRegistry(1, false)
366-
val (List(arg), None) = formalArgsRegistry.genFormalArgs()
366+
val (List(arg), None) = formalArgsRegistry.genFormalArgs(): @unchecked
367367
val body = genOverloadDispatchSameArgc(jsName, formalArgsRegistry,
368368
setters.map(new ExportedSymbol(_, static)), jstpe.AnyType, None)
369369
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
@@ -391,7 +391,7 @@ object desugar {
391391

392392
/** The expansion of a class definition. See inline comments for what is involved */
393393
def classDef(cdef: TypeDef)(using Context): Tree = {
394-
val impl @ Template(constr0, _, self, _) = cdef.rhs
394+
val impl @ Template(constr0, _, self, _) = cdef.rhs: @unchecked
395395
val className = normalizeName(cdef, impl).asTypeName
396396
val parents = impl.parents
397397
val mods = cdef.mods
@@ -674,7 +674,7 @@ object desugar {
674674
.withMods(companionMods | Synthetic))
675675
.withSpan(cdef.span).toList
676676
if (companionDerived.nonEmpty)
677-
for (modClsDef @ TypeDef(_, _) <- mdefs)
677+
for (case modClsDef @ TypeDef(_, _) <- mdefs)
678678
modClsDef.putAttachment(DerivingCompanion, impl.srcPos.startPos)
679679
mdefs
680680
}
@@ -744,7 +744,7 @@ object desugar {
744744

745745
enumCompanionRef match {
746746
case ref: TermRefTree => // have the enum import watch the companion object
747-
val (modVal: ValDef) :: _ = companions
747+
val (modVal: ValDef) :: _ = companions: @unchecked
748748
ref.watching(modVal)
749749
case _ =>
750750
}
@@ -1168,7 +1168,7 @@ object desugar {
11681168

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

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

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

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

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

153153
private def transformAllParamss(paramss: List[ParamClause]): (TreeTypeMap, List[ParamClause]) = paramss match
154154
case params :: paramss1 =>
155-
val (tmap1, params1: ParamClause) = (params: @unchecked) match
155+
val (tmap1, params1: ParamClause) = ((params: @unchecked) match
156156
case ValDefs(vparams) => transformDefs(vparams)
157157
case TypeDefs(tparams) => transformDefs(tparams)
158+
): @unchecked
158159
val (tmap2, paramss2) = tmap1.transformAllParamss(paramss1)
159160
(tmap2, params1 :: paramss2)
160161
case nil =>

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

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

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ object Settings:
8383
}
8484

8585
def tryToSet(state: ArgsSummary): ArgsSummary = {
86-
val ArgsSummary(sstate, arg :: args, errors, warnings) = state
86+
val ArgsSummary(sstate, arg :: args, errors, warnings) = state: @unchecked
8787
def update(value: Any, args: List[String]): ArgsSummary =
8888
var dangers = warnings
8989
val value1 =

0 commit comments

Comments
 (0)