Skip to content

Commit 9039a77

Browse files
Printing hack for case _ =>
This is a hack to tell `case _ =>` and `case Any =>` apart while printing match type error messages. At this point in the compilation pipeline both `pat` types =:= Any, however because of the slight difference in representation we are able to restore the original syntax. Here is what `pat.toString` gives in each case: // case _ => (TypeRef(ThisType(TypeRef(NoPrefix,module class scala)),class Any)) // case Any => (TypeRef(TermRef(ThisType(TypeRef(NoPrefix,module class <root>)),object scala),class Any)) The second case doesn't `eq defn.AnyType` because it starts from <root>, and thus doesn't match the pattern added in this commit.
1 parent b402193 commit 9039a77

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ object MatchTypeTrace:
7777

7878
private def caseText(tp: Type)(using Context): String = tp match
7979
case tp: HKTypeLambda => caseText(tp.resultType)
80+
case defn.MatchCase(any, body) if any eq defn.AnyType => i"case _ => $body"
8081
case defn.MatchCase(pat, body) => i"case $pat => $body"
8182
case _ => i"case $tp"
8283

0 commit comments

Comments
 (0)