@@ -68,7 +68,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
6868
6969 override protected def recursionLimitExceeded (): Unit = {}
7070
71- protected val PrintableFlags : FlagSet = (SourceModifierFlags | Module | Local ).toCommonFlags
71+ protected def PrintableFlags (isType : Boolean ): FlagSet = {
72+ if (isType) TypeSourceModifierFlags | Module | Local
73+ else TermSourceModifierFlags | Module | Local
74+ }.toCommonFlags
7275
7376 override def nameString (name : Name ): String =
7477 if (ctx.settings.YdebugNames .value) name.debugString else name.toString
@@ -440,7 +443,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
440443 case tree @ TypeDef (name, rhs) =>
441444 def typeDefText (tparamsText : => Text , rhsText : => Text ) =
442445 dclTextOr(tree) {
443- modText(tree.mods, tree.symbol, keywordStr(" type" )) ~~ (varianceText(tree.mods) ~ typeText(nameIdText(tree))) ~
446+ modText(tree.mods, tree.symbol, keywordStr(" type" ), isType = true ) ~~
447+ (varianceText(tree.mods) ~ typeText(nameIdText(tree))) ~
444448 withEnclosingDef(tree) { tparamsText ~ rhsText }
445449 }
446450 def recur (rhs : Tree , tparamsTxt : => Text ): Text = rhs match {
@@ -479,7 +483,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
479483 else toText(t)
480484 case tree @ ModuleDef (name, impl) =>
481485 withEnclosingDef(tree) {
482- modText(tree.mods, NoSymbol , keywordStr(" object" )) ~~ nameIdText(tree) ~ toTextTemplate(impl)
486+ modText(tree.mods, NoSymbol , keywordStr(" object" ), isType = false ) ~~
487+ nameIdText(tree) ~ toTextTemplate(impl)
483488 }
484489 case SymbolLit (str) =>
485490 " '" + str
@@ -534,8 +539,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
534539 t ~ cxBoundToText(cxb)
535540 }
536541 case PatDef (mods, pats, tpt, rhs) =>
537- modText(mods, NoSymbol , keywordStr(" val" )) ~~ toText(pats, " , " ) ~ optAscription(tpt) ~
538- optText(rhs)(" = " ~ _)
542+ modText(mods, NoSymbol , keywordStr(" val" ), isType = false ) ~ ~
543+ toText(pats, " , " ) ~ optAscription(tpt) ~ optText(rhs)(" = " ~ _)
539544 case ParsedTry (expr, handler, finalizer) =>
540545 changePrec(GlobalPrec ) {
541546 keywordStr(" try " ) ~ toText(expr) ~ " " ~ keywordStr(" catch" ) ~ " {" ~ toText(handler) ~ " }" ~ optText(finalizer)(keywordStr(" finally " ) ~ _)
@@ -658,7 +663,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
658663 protected def valDefToText [T >: Untyped ](tree : ValDef [T ]): Text = {
659664 import untpd .{modsDeco => _ }
660665 dclTextOr(tree) {
661- modText(tree.mods, tree.symbol, keywordStr(if (tree.mods is Mutable ) " var" else " val" )) ~~
666+ modText(tree.mods, tree.symbol, keywordStr(if (tree.mods is Mutable ) " var" else " val" ), isType = false ) ~~
662667 valDefText(nameIdText(tree)) ~ optAscription(tree.tpt) ~
663668 withEnclosingDef(tree) { optText(tree.rhs)(" = " ~ _) }
664669 }
@@ -667,7 +672,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
667672 protected def defDefToText [T >: Untyped ](tree : DefDef [T ]): Text = {
668673 import untpd .{modsDeco => _ }
669674 dclTextOr(tree) {
670- val prefix = modText(tree.mods, tree.symbol, keywordStr(" def" )) ~~ valDefText(nameIdText(tree))
675+ val prefix = modText(tree.mods, tree.symbol, keywordStr(" def" ), isType = false ) ~~ valDefText(nameIdText(tree))
671676 withEnclosingDef(tree) {
672677 addVparamssText(prefix ~ tparamsText(tree.tparams), tree.vparamss) ~ optAscription(tree.tpt) ~
673678 optText(tree.rhs)(" = " ~ _)
@@ -682,7 +687,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
682687 val prefix : Text =
683688 if (vparamss.isEmpty || primaryConstrs.nonEmpty) tparamsTxt
684689 else {
685- var modsText = modText(constr.mods, constr.symbol, " " )
690+ var modsText = modText(constr.mods, constr.symbol, " " , isType = false )
686691 if (! modsText.isEmpty) modsText = " " ~ modsText
687692 if (constr.mods.hasAnnotations && ! constr.mods.hasFlags) modsText = modsText ~~ " this"
688693 withEnclosingDef(constr) { addVparamssText(tparamsTxt ~~ modsText, vparamss) }
@@ -709,7 +714,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
709714 }
710715
711716 protected def templateText (tree : TypeDef , impl : Template ): Text = {
712- val decl = modText(tree.mods, tree.symbol, keywordStr(if ((tree).mods is Trait ) " trait" else " class" ))
717+ val decl = modText(tree.mods, tree.symbol, keywordStr(if ((tree).mods is Trait ) " trait" else " class" ), isType = true )
713718 decl ~~ typeText(nameIdText(tree)) ~ withEnclosingDef(tree) { toTextTemplate(impl) } ~
714719 (if (tree.hasType && ctx.settings.verbose.value) i " [decls = ${tree.symbol.info.decls}] " else " " )
715720 }
@@ -732,12 +737,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
732737
733738 protected def annotText (tree : untpd.Tree ): Text = " @" ~ constrText(tree) // DD
734739
735- protected def modText (mods : untpd.Modifiers , sym : Symbol , kw : String , suppress : FlagSet = EmptyFlags ): Text = { // DD
740+ protected def modText (mods : untpd.Modifiers , sym : Symbol , kw : String , isType : Boolean ): Text = { // DD
736741 val suppressKw = if (enclDefIsClass) mods is ParamAndLocal else mods is Param
737742 var flagMask =
738743 if (ctx.settings.YdebugFlags .value) AnyFlags
739- else if (suppressKw) PrintableFlags &~ Private &~ suppress
740- else PrintableFlags &~ suppress
744+ else if (suppressKw) PrintableFlags (isType) &~ Private
745+ else PrintableFlags (isType)
741746 if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= Implicit // drop implicit from classes
742747 val flags = (if (sym.exists) sym.flags else (mods.flags)) & flagMask
743748 val flagsText = if (flags.isEmpty) " " else keywordStr(flags.toString)
@@ -811,7 +816,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
811816 else {
812817 var flags = sym.flagsUNSAFE
813818 if (flags is TypeParam ) flags = flags &~ Protected
814- Text ((flags & PrintableFlags ).flagStrings map (flag => stringToText(keywordStr(flag))), " " )
819+ Text ((flags & PrintableFlags (sym.isType) ).flagStrings map (flag => stringToText(keywordStr(flag))), " " )
815820 }
816821
817822 override def toText (denot : Denotation ): Text = denot match {
0 commit comments