Skip to content

Commit f6891b5

Browse files
authored
Merge pull request #6593 from dotty-staging/fix-620
Fix #620: show privateWithin in tree printing
2 parents 831dec3 + 8a7e01e commit f6891b5

File tree

4 files changed

+12
-9
lines changed

4 files changed

+12
-9
lines changed

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

+8-5
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

+1-1
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ class PlainPrinter(_ctx: Context) extends Printer {
404404

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

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
813813
val rawFlags = if (sym.exists) sym.flags else mods.flags
814814
if (rawFlags.is(Param)) flagMask = flagMask &~ Given
815815
val flags = rawFlags & flagMask
816-
val flagsText = if (flags.isEmpty) "" else keywordStr(flags.toString)
816+
val flagsText = if (flags.isEmpty) "" else keywordStr(flags.flagStrings(nameString(sym.privateWithin.name)).mkString(" "))
817817
val annotations =
818818
if (sym.exists) sym.annotations.filterNot(ann => dropAnnotForModText(ann.symbol)).map(_.tree)
819819
else mods.annotations.filterNot(tree => dropAnnotForModText(tree.symbol))
@@ -888,7 +888,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
888888
else {
889889
var flags = sym.flagsUNSAFE
890890
if (flags is TypeParam) flags = flags &~ Protected
891-
Text((flags & PrintableFlags(sym.isType)).flagStrings map (flag => stringToText(keywordStr(flag))), " ")
891+
Text((flags & PrintableFlags(sym.isType)).flagStrings(nameString(sym.privateWithin.name)) map (flag => stringToText(keywordStr(flag))), " ")
892892
}
893893

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

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

+1-1
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)