Skip to content

Commit 7766fe9

Browse files
Backport "fix: don't use color codes for pattern match code action" to LTS (#21991)
Backports #21120 to the LTS branch. PR submitted by the release tooling. [skip ci]
2 parents e50f921 + e2cacca commit 7766fe9

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

Diff for: compiler/src/dotty/tools/dotc/reporting/messages.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import printing.Formatting
1515
import ErrorMessageID.*
1616
import ast.Trees
1717
import config.{Feature, ScalaVersion}
18+
import transform.patmat.Space
19+
import transform.patmat.SpaceEngine
1820
import typer.ErrorReporting.{err, matchReductionAddendum, substitutableTypeSymbolsInScope}
1921
import typer.ProtoTypes.{ViewProto, SelectionProto, FunProto}
2022
import typer.Implicits.*
@@ -853,12 +855,13 @@ extends Message(LossyWideningConstantConversionID):
853855
|Write `.to$targetType` instead."""
854856
def explain(using Context) = ""
855857

856-
class PatternMatchExhaustivity(uncoveredCases: Seq[String], tree: untpd.Match)(using Context)
858+
class PatternMatchExhaustivity(uncoveredCases: Seq[Space], tree: untpd.Match)(using Context)
857859
extends Message(PatternMatchExhaustivityID) {
858860
def kind = MessageKind.PatternMatchExhaustivity
859861

860862
private val hasMore = uncoveredCases.lengthCompare(6) > 0
861-
val uncovered = uncoveredCases.take(6).mkString(", ")
863+
val uncovered = uncoveredCases.take(6).map(SpaceEngine.display).mkString(", ")
864+
private val casesWithoutColor = inContext(ctx.withoutColors)(uncoveredCases.map(SpaceEngine.display))
862865

863866
def msg(using Context) =
864867
val addendum = if hasMore then "(More unmatched cases are elided)" else ""
@@ -886,12 +889,12 @@ extends Message(PatternMatchExhaustivityID) {
886889
val pathes = List(
887890
ActionPatch(
888891
srcPos = endPos,
889-
replacement = uncoveredCases.map(c => indent(s"case $c => ???", startColumn))
892+
replacement = casesWithoutColor.map(c => indent(s"case $c => ???", startColumn))
890893
.mkString("\n", "\n", "")
891894
),
892895
)
893896
List(
894-
CodeAction(title = s"Insert missing cases (${uncoveredCases.size})",
897+
CodeAction(title = s"Insert missing cases (${casesWithoutColor.size})",
895898
description = None,
896899
patches = pathes
897900
)

Diff for: compiler/src/dotty/tools/dotc/transform/patmat/Space.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,7 @@ object SpaceEngine {
842842

843843
if uncovered.nonEmpty then
844844
val deduped = dedup(uncovered)
845-
report.warning(PatternMatchExhaustivity(deduped.map(display), m), m.selector)
845+
report.warning(PatternMatchExhaustivity(deduped, m), m.selector)
846846
}
847847

848848
private def reachabilityCheckable(sel: Tree)(using Context): Boolean =

0 commit comments

Comments
 (0)