diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 24d8e5a6793a..0c31d25f9e06 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -742,12 +742,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { def tparamsText[T >: Untyped](params: List[Tree[T]]): Text = "[" ~ toText(params, ", ") ~ "]" provided params.nonEmpty - def addVparamssText[T >: Untyped](txt: Text, vparamss: List[List[ValDef[T]]], isExtension: Boolean = false): Text = { - def paramsText(params: List[ValDef[T]]) = "(" ~ toText(params, ", ") ~ ")" - val (leading, paramss) = - if (isExtension && vparamss.nonEmpty) (paramsText(vparamss.head) ~ " " ~ txt, vparamss.tail) - else (txt, vparamss) - paramss.foldLeft(leading)((txt, params) => + def addVparamssText[T >: Untyped](leading: Text, vparamss: List[List[ValDef[T]]]): Text = { + vparamss.foldLeft(leading)((txt, params) => txt ~ (Str(" given ") provided params.nonEmpty && params.head.mods.is(Given)) ~ paramsText(params)) @@ -761,13 +757,19 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } } + private def paramsText[T>: Untyped](params: List[ValDef[T]]) = "(" ~ toText(params, ", ") ~ ")" + protected def defDefToText[T >: Untyped](tree: DefDef[T]): Text = { import untpd.{modsDeco => _} dclTextOr(tree) { - val prefix = modText(tree.mods, tree.symbol, keywordStr("def"), isType = false) ~~ valDefText(nameIdText(tree)) + val defKeyword = modText(tree.mods, tree.symbol, keywordStr("def"), isType = false) val isExtension = tree.hasType && tree.symbol.is(Extension) withEnclosingDef(tree) { - addVparamssText(prefix ~ tparamsText(tree.tparams), tree.vparamss, isExtension) ~ + val (prefix, vparamss) = + if(isExtension) (defKeyword ~~ paramsText(tree.vparamss.head) ~~ valDefText(nameIdText(tree)), tree.vparamss.tail) + else (defKeyword ~~ valDefText(nameIdText(tree)), tree.vparamss) + + addVparamssText(prefix ~ tparamsText(tree.tparams), vparamss) ~ optAscription(tree.tpt) ~ optText(tree.rhs)(" = " ~ _) } diff --git a/tests/printing/i620.check b/tests/printing/i620.check index ab622d1a69ad..c1bca2fb0bec 100644 --- a/tests/printing/i620.check +++ b/tests/printing/i620.check @@ -10,6 +10,8 @@ package O { private[A] def e: Int = 0 protected[A] def f: Int = 0 def g: Int = 0 + def g1(t: Int): Int = 0 + def (c: D.this.C) g1: Int = 0 } private[D] class E() extends Object() {} private class F() extends Object() {} diff --git a/tests/printing/i620.scala b/tests/printing/i620.scala index 2c22b8a2cbf9..a4e1be9261e3 100644 --- a/tests/printing/i620.scala +++ b/tests/printing/i620.scala @@ -12,6 +12,8 @@ class D { private[A] def e: Int = 0 protected[A] def f: Int = 0 def g: Int = 0 + def g1(t: Int) = 0 + def (c: C) g1 = 0 } private[D] class E