Skip to content

Commit 1703a04

Browse files
committed
Allow QuotePatterns.decode to decode higherOrderHoleWithTypes
1 parent 7bbf5ed commit 1703a04

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

compiler/src/dotty/tools/dotc/quoted/QuotePatterns.scala

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ object QuotePatterns:
260260
fun match
261261
// <quotes>.asInstanceOf[QuoteMatching].{ExprMatch,TypeMatch}.unapply[<typeBindings>, <resTypes>]
262262
case TypeApply(Select(Select(TypeApply(Select(quotes, _), _), _), _), typeBindings :: resTypes :: Nil) =>
263-
val bindings = unrollBindings(typeBindings)
263+
val bindings = unrollHkNestedPairsTypeTree(typeBindings)
264264
val addPattenSplice = new TreeMap {
265265
private val patternIterator = patterns.iterator.filter {
266266
case pat: Bind => !pat.symbol.name.is(PatMatGivenVarName)
@@ -272,6 +272,10 @@ object QuotePatterns:
272272
cpy.SplicePattern(tree)(patternIterator.next(), Nil, Nil)
273273
case Apply(patternHole, SeqLiteral(args, _) :: Nil) if patternHole.symbol == defn.QuotedRuntimePatterns_higherOrderHole =>
274274
cpy.SplicePattern(tree)(patternIterator.next(), Nil, args)
275+
case Apply(TypeApply(patternHole, List(_, targsTpe)), SeqLiteral(args, _) :: Nil) if patternHole.symbol == defn.QuotedRuntimePatterns_higherOrderHoleWithTypes =>
276+
// TODO-18271: error on ill-formed typed arguments?
277+
// TODO-18271: test case?
278+
cpy.SplicePattern(tree)(patternIterator.next(), unrollHkNestedPairsTypeTree(targsTpe), args)
275279
case _ => super.transform(tree)
276280
}
277281
val body = addPattenSplice.transform(shape) match
@@ -289,7 +293,7 @@ object QuotePatterns:
289293
case body => body
290294
cpy.QuotePattern(tree)(bindings, body, quotes)
291295

292-
private def unrollBindings(tree: Tree)(using Context): List[Tree] = tree match
296+
private def unrollHkNestedPairsTypeTree(tree: Tree)(using Context): List[Tree] = tree match
293297
case AppliedTypeTree(tupleN, bindings) if defn.isTupleClass(tupleN.symbol) => bindings // TupleN, 1 <= N <= 22
294-
case AppliedTypeTree(_, head :: tail :: Nil) => head :: unrollBindings(tail) // KCons or *:
298+
case AppliedTypeTree(_, head :: tail :: Nil) => head :: unrollHkNestedPairsTypeTree(tail) // KCons or *:
295299
case _ => Nil // KNil or EmptyTuple

0 commit comments

Comments
 (0)