@@ -135,27 +135,27 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
135135 def toTextTuple (args : List [Type ]): Text =
136136 " (" ~ argsText(args) ~ " )"
137137
138- def toTextFunction (args : List [Type ], isContextual : Boolean , isErased : Boolean ): Text =
138+ def toTextFunction (args : List [Type ], isGiven : Boolean , isErased : Boolean ): Text =
139139 changePrec(GlobalPrec ) {
140140 val argStr : Text =
141141 if args.length == 2
142142 && ! defn.isTupleType(args.head)
143- && ! isContextual && ! isErased
143+ && ! isGiven && ! isErased
144144 then
145145 atPrec(InfixPrec ) { argText(args.head) }
146146 else
147147 " ("
148- ~ ( keywordText(" given " ) provided isContextual )
149- ~ ( keywordText(" erased " ) provided isErased)
148+ ~ keywordText(" given " ). provided(isGiven )
149+ ~ keywordText(" erased " ). provided( isErased)
150150 ~ argsText(args.init)
151151 ~ " )"
152152 argStr ~ " => " ~ argText(args.last)
153153 }
154154
155155 def toTextDependentFunction (appType : MethodType ): Text =
156156 " ("
157- ~ ( keywordText(" given " ) provided appType.isImplicitMethod)
158- ~ ( keywordText(" erased " ) provided appType.isErasedMethod)
157+ ~ keywordText(" given " ). provided( appType.isImplicitMethod)
158+ ~ keywordText(" erased " ). provided( appType.isErasedMethod)
159159 ~ paramsText(appType)
160160 ~ " ) => "
161161 ~ toText(appType.resultType)
@@ -247,8 +247,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
247247 case _ => toTextGlobal(args, " , " )
248248 }
249249 " [applied to ("
250- ~ ( Str ( " given " ) provided tp.isContextualMethod)
251- ~ ( Str ( " erased " ) provided tp.isErasedMethod)
250+ ~ keywordText( " given " ). provided( tp.isContextualMethod)
251+ ~ keywordText( " erased " ). provided( tp.isErasedMethod)
252252 ~ argsText
253253 ~ " ) returning "
254254 ~ toText(resultType)
@@ -343,8 +343,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
343343 case id :: Nil => toText(id)
344344 case _ => " {" ~ Text (selectors map selectorText, " , " ) ~ " }"
345345 }
346- ( keywordText(" given " ) provided givenOnly) ~
347- toTextLocal(expr) ~ " ." ~ selectorsText
346+ keywordText(" given " ). provided( givenOnly)
347+ ~ toTextLocal(expr) ~ " ." ~ selectorsText
348348 }
349349
350350 tree match {
@@ -383,13 +383,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
383383 keywordStr(" '{" ) ~ toTextGlobal(args, " , " ) ~ keywordStr(" }" )
384384 else if (! printDebug && fun.hasType && fun.symbol == defn.InternalQuoted_exprSplice )
385385 keywordStr(" ${" ) ~ toTextGlobal(args, " , " ) ~ keywordStr(" }" )
386- else if (app.isGivenApply && ! homogenizedView)
387- changePrec(InfixPrec ) {
388- toTextLocal(fun) ~ " given " ~
389- (if (args.length == 1 ) toTextLocal(args.head) else " (" ~ toTextGlobal(args, " , " ) ~ " )" )
390- }
391386 else
392- toTextLocal(fun) ~ " (" ~ toTextGlobal(args, " , " ) ~ " )"
387+ toTextLocal(fun)
388+ ~ " ("
389+ ~ keywordText(" given " ).provided(app.isGivenApply && ! homogenizedView)
390+ ~ toTextGlobal(args, " , " )
391+ ~ " )"
393392 case tree : TypeApply =>
394393 typeApplyText(tree)
395394 case Literal (c) =>
@@ -493,7 +492,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
493492 if (lo eq hi) optText(lo)(" = " ~ _)
494493 else optText(lo)(" >: " ~ _) ~ optText(hi)(" <: " ~ _)
495494 case Bind (name, body) =>
496- (" given " : Text ).provided(tree.symbol.isOneOf(GivenOrImplicit ) && ! homogenizedView) ~ // Used for scala.quoted.Type in quote patterns (not pickled)
495+ keywordText (" given " ).provided(tree.symbol.isOneOf(GivenOrImplicit ) && ! homogenizedView) ~ // Used for scala.quoted.Type in quote patterns (not pickled)
497496 changePrec(InfixPrec ) { toText(name) ~ " @ " ~ toText(body) }
498497 case Alternative (trees) =>
499498 changePrec(OrPrec ) { toText(trees, " | " ) }
@@ -560,12 +559,12 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
560559 toText(id) ~ " \" " ~ Text (segments map segmentText, " " ) ~ " \" "
561560 case Function (args, body) =>
562561 var implicitSeen : Boolean = false
563- var contextual : Boolean = false
562+ var isGiven : Boolean = false
564563 var isErased : Boolean = false
565564 def argToText (arg : Tree ) = arg match {
566565 case arg @ ValDef (name, tpt, _) =>
567566 val implicitText =
568- if ((arg.mods.is(Given ))) { contextual = true ; " " }
567+ if ((arg.mods.is(Given ))) { isGiven = true ; " " }
569568 else if ((arg.mods.is(Erased ))) { isErased = true ; " " }
570569 else if ((arg.mods.is(Implicit )) && ! implicitSeen) { implicitSeen = true ; keywordStr(" implicit " ) }
571570 else " "
@@ -575,13 +574,14 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
575574 }
576575 val argsText = args match {
577576 case (arg @ ValDef (_, tpt, _)) :: Nil if tpt.isEmpty => argToText(arg)
578- case _ => " ( " ~ Text (args map argToText, " , " ) ~ " ) "
579- }
580- changePrec( GlobalPrec ) {
581- ( keywordText(" given " ) provided contextual) ~
582- (keywordText( " erased " ) provided isErased) ~
583- argsText ~ " => " ~ toText(body)
577+ case _ =>
578+ " ( "
579+ ~ keywordText( " given " ).provided(isGiven)
580+ ~ keywordText(" erased " ). provided(isErased)
581+ ~ Text (args.map(argToText), " , " )
582+ ~ " ) "
584583 }
584+ argsText ~ " => " ~ toText(body)
585585 case PolyFunction (targs, body) =>
586586 val targsText = " [" ~ Text (targs.map((arg : Tree ) => toText(arg)), " , " ) ~ " ]"
587587 changePrec(GlobalPrec ) {
@@ -761,6 +761,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
761761 txt ~
762762 (Str (" given " ) provided params.nonEmpty && params.head.mods.is(Given )) ~
763763 paramsText(params))
764+
764765 protected def valDefToText [T >: Untyped ](tree : ValDef [T ]): Text = {
765766 import untpd .{modsDeco => _ }
766767 dclTextOr(tree) {
@@ -770,7 +771,11 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
770771 }
771772 }
772773
773- private def paramsText [T >: Untyped ](params : List [ValDef [T ]]) = " (" ~ toText(params, " , " ) ~ " )"
774+ private def paramsText [T >: Untyped ](params : List [ValDef [T ]]) =
775+ " ("
776+ ~ keywordText(" given " ).provided(params.nonEmpty && params.head.mods.is(Given ))
777+ ~ toText(params, " , " )
778+ ~ " )"
774779
775780 protected def defDefToText [T >: Untyped ](tree : DefDef [T ]): Text = {
776781 import untpd .{modsDeco => _ }
0 commit comments