Skip to content

Commit 13e6695

Browse files
committed
Fix #7154: Adjust RefinedPrinter to handle extention methods
1 parent 518c426 commit 13e6695

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -742,12 +742,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
742742
def tparamsText[T >: Untyped](params: List[Tree[T]]): Text =
743743
"[" ~ toText(params, ", ") ~ "]" provided params.nonEmpty
744744

745-
def addVparamssText[T >: Untyped](txt: Text, vparamss: List[List[ValDef[T]]], isExtension: Boolean = false): Text = {
746-
def paramsText(params: List[ValDef[T]]) = "(" ~ toText(params, ", ") ~ ")"
747-
val (leading, paramss) =
748-
if (isExtension && vparamss.nonEmpty) (paramsText(vparamss.head) ~ " " ~ txt, vparamss.tail)
749-
else (txt, vparamss)
750-
paramss.foldLeft(leading)((txt, params) =>
745+
def addVparamssText[T >: Untyped](leading: Text, vparamss: List[List[ValDef[T]]]): Text = {
746+
vparamss.foldLeft(leading)((txt, params) =>
751747
txt ~
752748
(Str(" given ") provided params.nonEmpty && params.head.mods.is(Given)) ~
753749
paramsText(params))
@@ -761,13 +757,19 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
761757
}
762758
}
763759

760+
private def paramsText[T>: Untyped](params: List[ValDef[T]]) = "(" ~ toText(params, ", ") ~ ")"
761+
764762
protected def defDefToText[T >: Untyped](tree: DefDef[T]): Text = {
765763
import untpd.{modsDeco => _}
766764
dclTextOr(tree) {
767-
val prefix = modText(tree.mods, tree.symbol, keywordStr("def"), isType = false) ~~ valDefText(nameIdText(tree))
765+
val defKeyword = modText(tree.mods, tree.symbol, keywordStr("def"), isType = false)
768766
val isExtension = tree.hasType && tree.symbol.is(Extension)
769767
withEnclosingDef(tree) {
770-
addVparamssText(prefix ~ tparamsText(tree.tparams), tree.vparamss, isExtension) ~
768+
val (prefix, vparamss) =
769+
if(isExtension) (defKeyword ~~ paramsText(tree.vparamss.head) ~~ valDefText(nameIdText(tree)), tree.vparamss.tail)
770+
else (defKeyword ~~ valDefText(nameIdText(tree)), tree.vparamss)
771+
772+
addVparamssText(prefix ~ tparamsText(tree.tparams), vparamss) ~
771773
optAscription(tree.tpt) ~
772774
optText(tree.rhs)(" = " ~ _)
773775
}

tests/printing/i620.check

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ package O {
1010
private[A] def e: Int = 0
1111
protected[A] def f: Int = 0
1212
def g: Int = 0
13+
def g1(t: Int): Int = 0
14+
def (c: D.this.C) g1: Int = 0
1315
}
1416
private[D] class E() extends Object() {}
1517
private class F() extends Object() {}

tests/printing/i620.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ class D {
1212
private[A] def e: Int = 0
1313
protected[A] def f: Int = 0
1414
def g: Int = 0
15+
def g1(t: Int) = 0
16+
def (c: C) g1 = 0
1517
}
1618

1719
private[D] class E

0 commit comments

Comments
 (0)