Skip to content

Commit 553aa8a

Browse files
committed
Refactor printing of capture sets
1 parent 63b6aae commit 553aa8a

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

compiler/src/dotty/tools/dotc/cc/CaptureSet.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ sealed abstract class CaptureSet extends Showable:
320320
Annotation(CaptureAnnotation(this, boxed = false)(cls).tree)
321321

322322
override def toText(printer: Printer): Text =
323-
Str("{") ~ Text(elems.toList.map(printer.toTextCaptureRef), ", ") ~ Str("}") ~~ description
323+
printer.toTextCaptureSet(this)
324324

325325
object CaptureSet:
326326
type Refs = SimpleIdentitySet[CaptureRef]

compiler/src/dotty/tools/dotc/printing/PlainPrinter.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
156156
if printDebug && !cs.isConst then cs.toString
157157
else if ctx.settings.YccDebug.value then cs.show
158158
else if cs == CaptureSet.Fluid then "<fluid>"
159-
else if !cs.isConst && cs.elems.isEmpty then Str("?") ~ nestingLevelStr
160-
else "{" ~ Text(cs.elems.toList.map(toTextCaptureRef), ", ") ~ "}" ~ nestingLevelStr
159+
else if !cs.isConst && cs.elems.isEmpty then Str("?") ~~ cs.description ~ nestingLevelStr
160+
else "{" ~ Text(cs.elems.toList.map(toTextCaptureRef), ", ") ~ "}" ~~ cs.description ~ nestingLevelStr
161161

162162
/** Print capturing type, overridden in RefinedPrinter to account for
163163
* capturing function types.

compiler/src/dotty/tools/dotc/printing/Printer.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import Types.{Type, SingletonType, LambdaParam, NamedType},
1010
import typer.Implicits.SearchResult
1111
import util.SourcePosition
1212
import typer.ImportInfo
13+
import cc.CaptureSet
1314

1415
import scala.annotation.internal.sharable
1516

@@ -106,6 +107,9 @@ abstract class Printer {
106107
/** Textual representation of a reference in a capture set */
107108
def toTextCaptureRef(tp: Type): Text
108109

110+
/** Textual representation of a reference in a capture set */
111+
def toTextCaptureSet(cs: CaptureSet): Text
112+
109113
/** Textual representation of symbol's declaration */
110114
def dclText(sym: Symbol): Text
111115

0 commit comments

Comments
 (0)