diff --git a/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala b/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala index 392d719cfefd..ee4ff251ff8b 100644 --- a/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/DecompilerPrinter.scala @@ -1,6 +1,6 @@ package dotty.tools.dotc.printing -import dotty.tools.dotc.ast.Trees.{Closure, DefDef, Untyped, ValDef} +import dotty.tools.dotc.ast.Trees._ import dotty.tools.dotc.ast.untpd.{PackageDef, Template, TypeDef} import dotty.tools.dotc.ast.{Trees, untpd} import dotty.tools.dotc.printing.Texts._ @@ -51,4 +51,10 @@ class DecompilerPrinter(_ctx: Context) extends RefinedPrinter(_ctx) { } } } + + override protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text = { + if (tree.symbol eq defn.quoteMethod) "'" + else if (tree.symbol eq defn.typeQuoteMethod) "'[" ~ toTextGlobal(tree.args, ", ") ~ "]" + else super.typeApplyText(tree) + } } diff --git a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala index 48bc992f8a47..447c033a4d18 100644 --- a/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/compiler/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -229,7 +229,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { protected def blockText[T >: Untyped](trees: List[Tree[T]]): Text = ("{" ~ toText(trees, "\n") ~ "}").close - override def toText[T >: Untyped](tree: Tree[T]): Text = controlled { + protected def typeApplyText[T >: Untyped](tree: TypeApply[T]): Text = + toTextLocal(tree.fun) ~ "[" ~ toTextGlobal(tree.args, ", ") ~ "]" + + protected def toTextCore[T >: Untyped](tree: Tree[T]): Text = { import untpd.{modsDeco => _, _} def isLocalThis(tree: Tree) = tree.typeOpt match { @@ -274,7 +277,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case _ => toTextGlobal(arg) } - def toTextCore(tree: Tree): Text = tree match { + tree match { case id: Trees.BackquotedIdent[_] if !homogenizedView => "`" ~ toText(id.name) ~ "`" case id: Trees.SearchFailureIdent[_] => @@ -308,8 +311,8 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { } else toTextLocal(fun) ~ "(" ~ toTextGlobal(args, ", ") ~ ")" - case TypeApply(fun, args) => - toTextLocal(fun) ~ "[" ~ toTextGlobal(args, ", ") ~ "]" + case tree: TypeApply => + typeApplyText(tree) case Literal(c) => tree.typeOpt match { case ConstantType(tc) => withPos(toText(tc), tree.pos) @@ -511,6 +514,10 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { case _ => tree.fallbackToText(this) } + } + + override def toText[T >: Untyped](tree: Tree[T]): Text = controlled { + import untpd.{modsDeco => _, _} var txt = toTextCore(tree) @@ -550,7 +557,7 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { if (ctx.settings.YprintPosSyms.value && tree.isDef) txt = (txt ~ s"@@(${tree.symbol.name}=" ~ tree.symbol.pos.toString ~ ")").close - } + } if (ctx.settings.YshowTreeIds.value) txt = (txt ~ "#" ~ tree.uniqueId.toString).close tree match { diff --git a/tests/run-with-compiler/quote-nested-1.check b/tests/run-with-compiler/quote-nested-1.check index 2378a7f62ea6..1ab350bb1762 100644 --- a/tests/run-with-compiler/quote-nested-1.check +++ b/tests/run-with-compiler/quote-nested-1.check @@ -1 +1 @@ -.'[Int](3) +'(3) diff --git a/tests/run-with-compiler/quote-nested-2.check b/tests/run-with-compiler/quote-nested-2.check index aea924902147..90df317c6cb6 100644 --- a/tests/run-with-compiler/quote-nested-2.check +++ b/tests/run-with-compiler/quote-nested-2.check @@ -1,4 +1,4 @@ { - val a: quoted.Expr[Int] = .'[Int](4) + val a: quoted.Expr[Int] = '(4) a } diff --git a/tests/run-with-compiler/quote-nested-4.check b/tests/run-with-compiler/quote-nested-4.check index ff8256f4afe7..5d37730e8890 100644 --- a/tests/run-with-compiler/quote-nested-4.check +++ b/tests/run-with-compiler/quote-nested-4.check @@ -1,4 +1,4 @@ { - val t: quoted.Type[String] = .type_'[String] + val t: quoted.Type[String] = '[String] t: quoted.Type[String] } diff --git a/tests/run-with-compiler/quote-nested-5.check b/tests/run-with-compiler/quote-nested-5.check index aea924902147..90df317c6cb6 100644 --- a/tests/run-with-compiler/quote-nested-5.check +++ b/tests/run-with-compiler/quote-nested-5.check @@ -1,4 +1,4 @@ { - val a: quoted.Expr[Int] = .'[Int](4) + val a: quoted.Expr[Int] = '(4) a }