Skip to content

Commit d7946bf

Browse files
Make match types with no matching cases not an error
Modify the MatchReducer to return NoType in the case of no matches, rather than throwing a MatchTypeReductionError. This makes it consistent with the other match type reduction failures, where being stuck does not result in an error, but simply in an unreduced match type. We still get the explanations of the underlying error in the MatchTypeTrace, but in positions which need the reduction for conformance, rather than at application site of the match type.
1 parent 5becaac commit d7946bf

File tree

3 files changed

+3
-6
lines changed

3 files changed

+3
-6
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3594,8 +3594,8 @@ class MatchReducer(initctx: Context) extends TypeComparer(initctx) {
35943594
MatchTypeTrace.emptyScrutinee(scrut)
35953595
NoType
35963596
case Nil =>
3597-
val casesText = MatchTypeTrace.noMatchesText(scrut, cases)
3598-
throw MatchTypeReductionError(em"Match type reduction $casesText")
3597+
MatchTypeTrace.noMatches(scrut, cases)
3598+
NoType
35993599

36003600
inFrozenConstraint(recur(cases))
36013601
}

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,6 @@ object TypeError:
5353
def toMessage(using Context) = msg
5454
end TypeError
5555

56-
class MatchTypeReductionError(msg: Message)(using Context) extends TypeError:
57-
def toMessage(using Context) = msg
58-
5956
class MalformedType(pre: Type, denot: Denotation, absMembers: Set[Name])(using Context) extends TypeError:
6057
def toMessage(using Context) = em"malformed type: $pre is not a legal prefix for $denot because it contains abstract type member${if (absMembers.size == 1) "" else "s"} ${absMembers.mkString(", ")}"
6158

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ trait ImplicitRunInfo:
663663
traverseChildren(t)
664664
case t =>
665665
traverseChildren(t)
666-
traverse(try t.normalized catch case _: MatchTypeReductionError => t)
666+
traverse(t.normalized)
667667
catch case ex: Throwable => handleRecursive("collectParts of", t.show, ex)
668668

669669
def apply(tp: Type): collection.Set[Type] =

0 commit comments

Comments
 (0)