Skip to content

Commit 4867326

Browse files
committed
Fix switch warning criterion
1 parent 27a8c34 commit 4867326

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

compiler/src/dotty/tools/dotc/transform/PatternMatcher.scala

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -969,16 +969,21 @@ object PatternMatcher {
969969
case Block(_, Match(_, cases)) => cases
970970
case _ => Nil
971971
}
972-
def numTypes(cdefs: List[CaseDef]): Int = {
973-
def patTypes(pat: Tree): List[Type] = pat match {
974-
case Alternative(pats) => pats.flatMap(patTypes)
975-
case _ => pat.tpe :: Nil
976-
}
977-
val tpes = cdefs.flatMap(patTypes)
978-
tpes.toSet.size: Int // without the type ascription, testPickling fails because of #2840.
972+
def typesInPattern(pat: Tree): List[Type] = pat match {
973+
case Alternative(pats) => pats.flatMap(typesInPattern)
974+
case _ => pat.tpe :: Nil
979975
}
980-
if (numTypes(resultCases) < numTypes(original.cases))
976+
def typesInCases(cdefs: List[CaseDef]): List[Type] =
977+
cdefs.flatMap(cdef => typesInPattern(cdef.pat))
978+
def numTypes(cdefs: List[CaseDef]): Int =
979+
typesInCases(cdefs).toSet.size: Int // without the type ascription, testPickling fails because of #2840.
980+
if (numTypes(resultCases) < numTypes(original.cases)) {
981+
patmatch.println(i"switch warning for ${ctx.compilationUnit}")
982+
patmatch.println(i"original types: ${typesInCases(original.cases)}%, %")
983+
patmatch.println(i"switch types : ${typesInCases(resultCases)}%, %")
984+
patmatch.println(i"tree = $result")
981985
ctx.warning(UnableToEmitSwitch(), original.pos)
986+
}
982987
case _ =>
983988
}
984989

0 commit comments

Comments
 (0)