Skip to content

Commit 962466a

Browse files
committed
Retype with QuotedPattern mode
1 parent 53b75e6 commit 962466a

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -742,13 +742,13 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) {
742742
val spliceTypeText = (keywordStr("[") ~ toTextGlobal(tree.typeOpt) ~ keywordStr("]")).provided(printDebug && tree.typeOpt.exists)
743743
keywordStr("$") ~ spliceTypeText ~ keywordStr("{") ~ toTextGlobal(expr) ~ keywordStr("}")
744744
case tree @ QuotePattern(bindings, body, quotes) =>
745-
// TODO print quotes for debugging
745+
val quotesText = (keywordStr("<") ~ toText(quotes) ~ keywordStr(">")).provided(printDebug)
746746
val bindingsText = bindings.map(binding => {
747747
keywordStr("type ") ~ toText(binding.symbol.name) ~ toText(binding.symbol.info) ~ "; "
748748
}).reduceLeft(_ ~~ _).provided(bindings.nonEmpty)
749749
val open = if (body.isTerm) keywordStr("{") else keywordStr("[")
750750
val close = if (body.isTerm) keywordStr("}") else keywordStr("]")
751-
keywordStr("'") ~ open ~ bindingsText ~ toTextGlobal(body) ~ close
751+
keywordStr("'") ~ quotesText ~ open ~ bindingsText ~ toTextGlobal(body) ~ close
752752
case SplicePattern(pattern, args) =>
753753
val spliceTypeText = (keywordStr("[") ~ toTextGlobal(tree.typeOpt) ~ keywordStr("]")).provided(printDebug && tree.typeOpt.exists)
754754
keywordStr("$") ~ spliceTypeText ~ {

compiler/src/dotty/tools/dotc/typer/ReTyper.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ class ReTyper(nestingLevel: Int = 0) extends Typer(nestingLevel) with ReChecking
114114
override def typedQuotePattern(tree: untpd.QuotePattern, pt: Type)(using Context): Tree =
115115
assertTyped(tree)
116116
val bindings1 = tree.bindings.map(typed(_))
117-
val bodyCtx = quoteContext.retractMode(Mode.Pattern)//.addMode(Mode.QuotedPattern)
117+
val bodyCtx = quoteContext.retractMode(Mode.Pattern).addMode(Mode.QuotedPattern)
118118
val body1 = typed(tree.body, tree.bodyType)(using bodyCtx)
119119
val quotes1 = typed(tree.quotes, defn.QuotesClass.typeRef)
120120
untpd.cpy.QuotePattern(tree)(bindings1, body1, quotes1).withType(tree.typeOpt)
@@ -126,7 +126,7 @@ class ReTyper(nestingLevel: Int = 0) extends Typer(nestingLevel) with ReChecking
126126
val patternTpe =
127127
if args1.isEmpty then tree.typeOpt
128128
else defn.FunctionType(args1.size).appliedTo(args1.map(_.tpe) :+ tree.typeOpt)
129-
val bodyCtx = spliceContext.addMode(Mode.Pattern)
129+
val bodyCtx = spliceContext.addMode(Mode.Pattern).retractMode(Mode.QuotedPattern)
130130
val body1 = typed(tree.body, defn.QuotedExprClass.typeRef.appliedTo(patternTpe))(using bodyCtx)
131131
val args = tree.args.mapconserve(typedExpr(_))
132132
untpd.cpy.SplicePattern(tree)(body1, args1).withType(tree.typeOpt)

0 commit comments

Comments
 (0)