Skip to content

Commit 6f2c093

Browse files
committed
New setting -Ycc-debug for more info on capture variables
1 parent 5dacf52 commit 6f2c093

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ private sealed trait YSettings:
301301
val YrequireTargetName: Setting[Boolean] = BooleanSetting("-Yrequire-targetName", "Warn if an operator is defined without a @targetName annotation")
302302
val Yrecheck: Setting[Boolean] = BooleanSetting("-Yrecheck", "Run type rechecks (test only)")
303303
val Ycc: Setting[Boolean] = BooleanSetting("-Ycc", "Check captured references")
304+
val YccDebug: Setting[Boolean] = BooleanSetting("-Ycc-debug", "Debug info for captured references")
304305

305306
/** Area-specific debug output */
306307
val YexplainLowlevel: Setting[Boolean] = BooleanSetting("-Yexplain-lowlevel", "When explaining type errors, show types at a lower level.")

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import util.SourcePosition
1515
import scala.util.control.NonFatal
1616
import scala.annotation.switch
1717
import config.Config
18-
import cc.CapturingType
18+
import cc.{CapturingType, CaptureSet}
1919

2020
class PlainPrinter(_ctx: Context) extends Printer {
2121
/** The context of all public methods in Printer and subclasses.
@@ -189,13 +189,20 @@ class PlainPrinter(_ctx: Context) extends Printer {
189189
(" <: " ~ toText(bound) provided !bound.isAny)
190190
}.close
191191
case CapturingType(parent, refs, boxed) =>
192+
def refsId = refs match
193+
case refs: CaptureSet.Var if ctx.settings.YccDebug.value => refs.id.toString
194+
case _ => ""
192195
def box = Str("box ") provided boxed
193196
if printDebug && !refs.isConst then
194197
changePrec(GlobalPrec)(box ~ s"$refs " ~ toText(parent))
195198
else if !refs.isConst && refs.elems.isEmpty then
196-
changePrec(GlobalPrec)("? " ~ toText(parent))
199+
changePrec(GlobalPrec)("?" ~ refsId ~ " " ~ toText(parent))
197200
else if Config.printCaptureSetsAsPrefix then
198-
changePrec(GlobalPrec)(box ~ "{" ~ Text(refs.elems.toList.map(toTextCaptureRef), ", ") ~ "} " ~ toText(parent))
201+
changePrec(GlobalPrec)(
202+
box ~ "{"
203+
~ Text(refs.elems.toList.map(toTextCaptureRef), ", ")
204+
~ "}" ~ refsId
205+
~ " " ~ toText(parent))
199206
else
200207
changePrec(InfixPrec)(toText(parent) ~ " retains " ~ box ~ toText(refs.toRetainsTypeArg))
201208
case tp: PreviousErrorType if ctx.settings.XprintTypes.value =>

0 commit comments

Comments
 (0)