Skip to content

Commit 2f6db91

Browse files
committed
Fix switch warning criterion
1 parent 493a1f7 commit 2f6db91

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
@@ -967,16 +967,21 @@ object PatternMatcher {
967967
case Block(_, Match(_, cases)) => cases
968968
case _ => Nil
969969
}
970-
def numTypes(cdefs: List[CaseDef]): Int = {
971-
def patTypes(pat: Tree): List[Type] = pat match {
972-
case Alternative(pats) => pats.flatMap(patTypes)
973-
case _ => pat.tpe :: Nil
974-
}
975-
val tpes = cdefs.flatMap(patTypes)
976-
tpes.toSet.size: Int // without the type ascription, testPickling fails because of #2840.
970+
def typesInPattern(pat: Tree): List[Type] = pat match {
971+
case Alternative(pats) => pats.flatMap(typesInPattern)
972+
case _ => pat.tpe :: Nil
977973
}
978-
if (numTypes(resultCases) < numTypes(original.cases))
974+
def typesInCases(cdefs: List[CaseDef]): List[Type] =
975+
cdefs.flatMap(cdef => typesInPattern(cdef.pat))
976+
def numTypes(cdefs: List[CaseDef]): Int =
977+
typesInCases(cdefs).toSet.size: Int // without the type ascription, testPickling fails because of #2840.
978+
if (numTypes(resultCases) < numTypes(original.cases)) {
979+
patmatch.println(i"switch warning for ${ctx.compilationUnit}")
980+
patmatch.println(i"original types: ${typesInCases(original.cases)}%, %")
981+
patmatch.println(i"switch types : ${typesInCases(resultCases)}%, %")
982+
patmatch.println(i"tree = $result")
979983
ctx.warning(UnableToEmitSwitch(), original.pos)
984+
}
980985
case _ =>
981986
}
982987

0 commit comments

Comments
 (0)