Skip to content

Commit 34c7058

Browse files
committed
Apply CR suggestion to use different functions
for methods/lambdas argument format
1 parent a7992a7 commit 34c7058

File tree

1 file changed

+26
-5
lines changed

1 file changed

+26
-5
lines changed

compiler/src/scala/quoted/runtime/impl/printers/SourceCode.scala

+26-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ object SourceCode {
158158
for paramClause <- paramss do
159159
paramClause match
160160
case TermParamClause(params) =>
161-
printArgsDefs(params)
161+
printMethdArgsDefs(params)
162162
case TypeParamClause(params) =>
163163
printTargsDefs(stats.collect { case targ: TypeDef => targ }.filter(_.symbol.isTypeParam).zip(params))
164164
}
@@ -313,7 +313,7 @@ object SourceCode {
313313
this += highlightKeyword("def ") += highlightValDef(name1)
314314
for clause <- paramss do
315315
clause match
316-
case TermParamClause(params) => printArgsDefs(params)
316+
case TermParamClause(params) => printMethdArgsDefs(params)
317317
case TypeParamClause(params) => printTargsDefs(params.zip(params))
318318
if (!isConstructor) {
319319
this += ": "
@@ -460,7 +460,7 @@ object SourceCode {
460460

461461
case tree @ Lambda(params, body) => // must come before `Block`
462462
inParens {
463-
printArgsDefs(params, isLambda = true)
463+
printLambdaArgsDefs(params)
464464
this += (if tree.tpe.isContextFunctionType then " ?=> " else " => ")
465465
printTree(body)
466466
}
@@ -804,14 +804,35 @@ object SourceCode {
804804
}
805805
}
806806

807-
private def printArgsDefs(args: List[ValDef], isLambda: Boolean = false)(using elideThis: Option[Symbol]): Unit = {
807+
private def printMethdArgsDefs(args: List[ValDef])(using elideThis: Option[Symbol]): Unit = {
808+
val argFlags = args match {
809+
case Nil => Flags.EmptyFlags
810+
case arg :: _ => arg.symbol.flags
811+
}
812+
inParens {
813+
if (argFlags.is(Flags.Implicit) && !argFlags.is(Flags.Given)) this += "implicit "
814+
if (argFlags.is(Flags.Given)) this += "using "
815+
816+
def printSeparated(list: List[ValDef]): Unit = list match {
817+
case Nil =>
818+
case x :: Nil => printParamDef(x)
819+
case x :: xs =>
820+
printParamDef(x)
821+
this += ", "
822+
printSeparated(xs)
823+
}
824+
825+
printSeparated(args)
826+
}
827+
}
828+
829+
private def printLambdaArgsDefs(args: List[ValDef])(using elideThis: Option[Symbol]): Unit = {
808830
val argFlags = args match {
809831
case Nil => Flags.EmptyFlags
810832
case arg :: _ => arg.symbol.flags
811833
}
812834
inParens {
813835
if (argFlags.is(Flags.Implicit) && !argFlags.is(Flags.Given)) this += "implicit "
814-
if (argFlags.is(Flags.Given) && !isLambda) this += "using "
815836

816837
def printSeparated(list: List[ValDef]): Unit = list match {
817838
case Nil =>

0 commit comments

Comments
 (0)