Skip to content

Commit ed21e27

Browse files
committed
Fix quote patterns with more than 22 splices
1 parent ee17211 commit ed21e27

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

compiler/src/dotty/tools/dotc/core/Definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -942,6 +942,7 @@ class Definitions {
942942
def TupleXXLModule(using Context): Symbol = TupleXXLClass.companionModule
943943

944944
def TupleXXL_fromIterator(using Context): Symbol = TupleXXLModule.requiredMethod("fromIterator")
945+
def TupleXXL_unapplySeq(using Context): Symbol = TupleXXLModule.requiredMethod(nme.unapplySeq)
945946

946947
@tu lazy val RuntimeTupleMirrorTypeRef: TypeRef = requiredClassRef("scala.runtime.TupleMirror")
947948

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ object QuotePatterns:
101101
.select(nme.unapply)
102102
.appliedToTypes(patternTypes)
103103
UnApply(tupleNUnapply, Nil, patterns, defn.tupleType(patternTypes))
104-
else ???
104+
else
105+
val tupleXXLUnapplySeq = ref(defn.TupleXXL_unapplySeq)
106+
val unapply = UnApply(tupleXXLUnapplySeq, Nil, patterns, defn.tupleType(patternTypes))
107+
Typed(unapply, TypeTree(defn.TupleXXLClass.typeRef))
105108

106109
val patType =
107110
val quotedTypes =
@@ -168,7 +171,7 @@ object QuotePatterns:
168171
val patterns = patternTuple match
169172
case _: Ident => Nil // EmptyTuple
170173
case UnApply(_, _, patterns) => patterns // TupleN
171-
// TODO: `*:`
174+
case Typed(UnApply(_, _, patterns), _) => patterns // TupleXXL
172175
case _ => return None
173176
val shape = implicits match
174177
case Apply(Select(Quote(shape, _), _), _) :: Nil => shape
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.quoted.*
2+
3+
inline def f(inline x: Any) = ${ fExpr('x) }
4+
5+
def fExpr(x: Expr[Any])(using Quotes): Expr[Any] =
6+
x match
7+
case '{ ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22, $x23, $x24) } =>
8+
'{ ($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22, $x23, $x24) }
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@main def Test =
2+
val t1 = f((1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24))
3+
val t2 = (1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24)
4+
assert(t1 == t2)

0 commit comments

Comments
 (0)