Skip to content

Commit 8a7e01e

Browse files
committed
Fix #620: show privateWithin in tree printing
1 parent c165638 commit 8a7e01e

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -107,19 +107,22 @@ object Flags {
107107
}
108108

109109
/** The list of non-empty names of flags that are set in this FlagSet */
110-
def flagStrings: Seq[String] = {
110+
def flagStrings(privateWithin: String): Seq[String] = {
111111
val rawStrings = (2 to MaxFlag).flatMap(flagString)
112-
if (this is Local)
112+
val scopeStr =
113+
if (this is Local) "this"
114+
else privateWithin
115+
if (privateWithin != "")
113116
rawStrings.filter(_ != "<local>").map {
114-
case "private" => "private[this]"
115-
case "protected" => "protected[this]"
117+
case "private" => s"private[$scopeStr]"
118+
case "protected" => s"protected[$scopeStr]"
116119
case str => str
117120
}
118121
else rawStrings
119122
}
120123

121124
/** The string representation of this flag set */
122-
override def toString: String = flagStrings.mkString(" ")
125+
override def toString: String = flagStrings("").mkString(" ")
123126
}
124127

125128
def termFlagSet(x: Long) = FlagSet(TERMS | x)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
401401

402402
/** String representation of symbol's flags */
403403
protected def toTextFlags(sym: Symbol): Text =
404-
Text(sym.flagsUNSAFE.flagStrings map stringToText, " ")
404+
Text(sym.flagsUNSAFE.flagStrings(nameString(sym.privateWithin.name)) map stringToText, " ")
405405

406406
/** String representation of symbol's variance or "" if not applicable */
407407
protected def varianceString(sym: Symbol): String = varianceString(sym.variance)

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
812812
val rawFlags = if (sym.exists) sym.flags else mods.flags
813813
if (rawFlags.is(Param)) flagMask = flagMask &~ Given
814814
val flags = rawFlags & flagMask
815-
val flagsText = if (flags.isEmpty) "" else keywordStr(flags.toString)
815+
val flagsText = if (flags.isEmpty) "" else keywordStr(flags.flagStrings(nameString(sym.privateWithin.name)).mkString(" "))
816816
val annotations =
817817
if (sym.exists) sym.annotations.filterNot(ann => dropAnnotForModText(ann.symbol)).map(_.tree)
818818
else mods.annotations.filterNot(tree => dropAnnotForModText(tree.symbol))
@@ -887,7 +887,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
887887
else {
888888
var flags = sym.flagsUNSAFE
889889
if (flags is TypeParam) flags = flags &~ Protected
890-
Text((flags & PrintableFlags(sym.isType)).flagStrings map (flag => stringToText(keywordStr(flag))), " ")
890+
Text((flags & PrintableFlags(sym.isType)).flagStrings(nameString(sym.privateWithin.name)) map (flag => stringToText(keywordStr(flag))), " ")
891891
}
892892

893893
override def toText(denot: Denotation): Text = denot match {

doc-tool/src/dotty/tools/dottydoc/model/factories.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ object factories {
2121

2222
def flags(t: Tree)(implicit ctx: Context): List[String] =
2323
(t.symbol.flags & (if (t.symbol.isType) TypeSourceModifierFlags else TermSourceModifierFlags))
24-
.flagStrings.toList
24+
.flagStrings(t.symbol.privateWithin.name.show).toList
2525
.filter(_ != "<trait>")
2626
.filter(_ != "interface")
2727
.filter(_ != "case")

0 commit comments

Comments
 (0)