Skip to content

Commit e7ef591

Browse files
dwijnandtgodzik
authored andcommitted
Fix fresh exhaustivity warnings in the compiler
1 parent d207772 commit e7ef591

File tree

3 files changed

+29
-33
lines changed

3 files changed

+29
-33
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
169169

170170
/* ---------------- helper utils for generating classes and fields ---------------- */
171171

172-
def genPlainClass(cd0: TypeDef) = cd0 match {
172+
def genPlainClass(cd0: TypeDef) = (cd0: @unchecked) match {
173173
case TypeDef(_, impl: Template) =>
174174
assert(cnode == null, "GenBCode detected nested methods.")
175175

compiler/src/dotty/tools/dotc/core/Comments.scala

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -405,15 +405,10 @@ object Comments {
405405
val Trim = "(?s)^[\\s&&[^\n\r]]*(.*?)\\s*$".r
406406

407407
val raw = ctx.docCtx.flatMap(_.docstring(sym).map(_.raw)).getOrElse("")
408-
defs(sym) ++= defines(raw).map {
409-
str => {
410-
val start = skipWhitespace(str, "@define".length)
411-
val (key, value) = str.splitAt(skipVariable(str, start))
412-
key.drop(start) -> value
413-
}
414-
} map {
415-
case (key, Trim(value)) =>
416-
variableName(key) -> value.replaceAll("\\s+\\*+$", "")
408+
defs(sym) ++= defines(raw).map { str =>
409+
val start = skipWhitespace(str, "@define".length)
410+
val (key, Trim(value)) = str.splitAt(skipVariable(str, start)): @unchecked
411+
variableName(key.drop(start)) -> value.replaceAll("\\s+\\*+$", "")
417412
}
418413
}
419414

compiler/src/dotty/tools/dotc/typer/Implicits.scala

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,29 +1290,30 @@ trait Implicits:
12901290
if alt1.isExtension then
12911291
// Fall back: if both results are extension method applications,
12921292
// compare the extension methods instead of their wrappers.
1293-
def stripExtension(alt: SearchSuccess) = methPart(stripApply(alt.tree)).tpe
1294-
(stripExtension(alt1), stripExtension(alt2)) match
1295-
case (ref1: TermRef, ref2: TermRef) =>
1296-
// ref1 and ref2 might refer to type variables owned by
1297-
// alt1.tstate and alt2.tstate respectively, to compare the
1298-
// alternatives correctly we need a TyperState that includes
1299-
// constraints from both sides, see
1300-
// tests/*/extension-specificity2.scala for test cases.
1301-
val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint
1302-
val constraintsIn2 = alt2.tstate.constraint ne ctx.typerState.constraint
1303-
def exploreState(alt: SearchSuccess): TyperState =
1304-
alt.tstate.fresh(committable = false)
1305-
val comparisonState =
1306-
if constraintsIn1 && constraintsIn2 then
1307-
exploreState(alt1).mergeConstraintWith(alt2.tstate)
1308-
else if constraintsIn1 then
1309-
exploreState(alt1)
1310-
else if constraintsIn2 then
1311-
exploreState(alt2)
1312-
else
1313-
ctx.typerState
1314-
1315-
diff = inContext(ctx.withTyperState(comparisonState)):
1293+
def stripExtension(alt: SearchSuccess) =
1294+
methPart(stripApply(alt.tree)).tpe: @unchecked match { case ref: TermRef => ref }
1295+
val ref1 = stripExtension(alt1)
1296+
val ref2 = stripExtension(alt2)
1297+
// ref1 and ref2 might refer to type variables owned by
1298+
// alt1.tstate and alt2.tstate respectively, to compare the
1299+
// alternatives correctly we need a TyperState that includes
1300+
// constraints from both sides, see
1301+
// tests/*/extension-specificity2.scala for test cases.
1302+
val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint
1303+
val constraintsIn2 = alt2.tstate.constraint ne ctx.typerState.constraint
1304+
def exploreState(alt: SearchSuccess): TyperState =
1305+
alt.tstate.fresh(committable = false)
1306+
val comparisonState =
1307+
if constraintsIn1 && constraintsIn2 then
1308+
exploreState(alt1).mergeConstraintWith(alt2.tstate)
1309+
else if constraintsIn1 then
1310+
exploreState(alt1)
1311+
else if constraintsIn2 then
1312+
exploreState(alt2)
1313+
else
1314+
ctx.typerState
1315+
1316+
diff = inContext(ctx.withTyperState(comparisonState)):
13161317
compare(ref1, ref2)
13171318
else // alt1 is a conversion, prefer extension alt2 over it
13181319
diff = -1

0 commit comments

Comments
 (0)