Skip to content

Commit 6d2277a

Browse files
committed
Print given clauses.
These were printed as old-style implicit parameters before.
1 parent 65922c4 commit 6d2277a

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

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

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
7171

7272
protected def PrintableFlags(isType: Boolean): FlagSet = {
7373
if (isType) TypeSourceModifierFlags | Module | Local
74-
else TermSourceModifierFlags | Module | Local
74+
else TermSourceModifierFlags | Module | Local | Given
7575
}.toCommonFlags
7676

7777
override def nameString(name: Name): String =
@@ -705,7 +705,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
705705
val (leading, paramss) =
706706
if (isExtension && vparamss.nonEmpty) (paramsText(vparamss.head) ~ " " ~ txt, vparamss.tail)
707707
else (txt, vparamss)
708-
(txt /: paramss)((txt, params) => txt ~ paramsText(params))
708+
(txt /: paramss)((txt, params) =>
709+
txt ~
710+
(Str(" given ") provided params.nonEmpty && hasFlag(params.head, Given)) ~
711+
paramsText(params))
709712
}
710713
protected def valDefToText[T >: Untyped](tree: ValDef[T]): Text = {
711714
import untpd.{modsDeco => _}
@@ -797,14 +800,19 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
797800
else if (suppressKw) PrintableFlags(isType) &~ Private
798801
else PrintableFlags(isType)
799802
if (homogenizedView && mods.flags.isTypeFlags) flagMask &~= ImplicitOrImplied // drop implicit/implied from classes
800-
val flags = (if (sym.exists) sym.flags else (mods.flags)) & flagMask
803+
val rawFlags = if (sym.exists) sym.flags else mods.flags
804+
if (rawFlags.is(Param)) flagMask = flagMask &~ Given
805+
val flags = rawFlags & flagMask
801806
val flagsText = if (flags.isEmpty) "" else keywordStr(flags.toString)
802807
val annotations =
803808
if (sym.exists) sym.annotations.filterNot(ann => dropAnnotForModText(ann.symbol)).map(_.tree)
804809
else mods.annotations.filterNot(tree => dropAnnotForModText(tree.symbol))
805810
Text(annotations.map(annotText), " ") ~~ flagsText ~~ (Str(kw) provided !suppressKw)
806811
}
807812

813+
private def hasFlag(tree: untpd.MemberDef, flag: FlagSet): Boolean =
814+
tree.mods.is(flag) || tree.symbol.is(flag)
815+
808816
def optText(name: Name)(encl: Text => Text): Text =
809817
if (name.isEmpty) "" else encl(toText(name))
810818

0 commit comments

Comments
 (0)