Skip to content

Commit 4072218

Browse files
committed
Fix fresh exhaustivity warnings in the compiler
1 parent c00dda3 commit 4072218

File tree

3 files changed

+30
-34
lines changed

3 files changed

+30
-34
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: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1383,30 +1383,31 @@ trait Implicits:
13831383
if alt1.isExtension then
13841384
// Fall back: if both results are extension method applications,
13851385
// compare the extension methods instead of their wrappers.
1386-
def stripExtension(alt: SearchSuccess) = methPart(stripApply(alt.tree)).tpe
1387-
(stripExtension(alt1), stripExtension(alt2)) match
1388-
case (ref1: TermRef, ref2: TermRef) =>
1389-
// ref1 and ref2 might refer to type variables owned by
1390-
// alt1.tstate and alt2.tstate respectively, to compare the
1391-
// alternatives correctly we need a TyperState that includes
1392-
// constraints from both sides, see
1393-
// tests/*/extension-specificity2.scala for test cases.
1394-
val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint
1395-
val constraintsIn2 = alt2.tstate.constraint ne ctx.typerState.constraint
1396-
def exploreState(alt: SearchSuccess): TyperState =
1397-
alt.tstate.fresh(committable = false)
1398-
val comparisonState =
1399-
if constraintsIn1 && constraintsIn2 then
1400-
exploreState(alt1).mergeConstraintWith(alt2.tstate)
1401-
else if constraintsIn1 then
1402-
exploreState(alt1)
1403-
else if constraintsIn2 then
1404-
exploreState(alt2)
1405-
else
1406-
ctx.typerState
1407-
1408-
diff = inContext(searchContext().withTyperState(comparisonState)):
1409-
compare(ref1, ref2, preferGeneral = true)
1386+
def stripExtension(alt: SearchSuccess) =
1387+
methPart(stripApply(alt.tree)).tpe: @unchecked match { case ref: TermRef => ref }
1388+
val ref1 = stripExtension(alt1)
1389+
val ref2 = stripExtension(alt2)
1390+
// ref1 and ref2 might refer to type variables owned by
1391+
// alt1.tstate and alt2.tstate respectively, to compare the
1392+
// alternatives correctly we need a TyperState that includes
1393+
// constraints from both sides, see
1394+
// tests/*/extension-specificity2.scala for test cases.
1395+
val constraintsIn1 = alt1.tstate.constraint ne ctx.typerState.constraint
1396+
val constraintsIn2 = alt2.tstate.constraint ne ctx.typerState.constraint
1397+
def exploreState(alt: SearchSuccess): TyperState =
1398+
alt.tstate.fresh(committable = false)
1399+
val comparisonState =
1400+
if constraintsIn1 && constraintsIn2 then
1401+
exploreState(alt1).mergeConstraintWith(alt2.tstate)
1402+
else if constraintsIn1 then
1403+
exploreState(alt1)
1404+
else if constraintsIn2 then
1405+
exploreState(alt2)
1406+
else
1407+
ctx.typerState
1408+
1409+
diff = inContext(searchContext().withTyperState(comparisonState)):
1410+
compare(ref1, ref2, preferGeneral = true)
14101411
else // alt1 is a conversion, prefer extension alt2 over it
14111412
diff = -1
14121413
if diff < 0 then alt2

0 commit comments

Comments
 (0)