Skip to content

Commit 1237511

Browse files
authoredMar 1, 2024··
Update varargs syntax in quote pattern examples (#2980)
Issue found in scala/scala3#19709
1 parent 2ab2130 commit 1237511

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed
 

‎_overviews/scala3-macros/tutorial/quotes.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,11 @@ given ToExpr[Boolean] with {
156156
given ToExpr[StringContext] with {
157157
def apply(stringContext: StringContext)(using Quotes) =
158158
val parts = Varargs(stringContext.parts.map(Expr(_)))
159-
'{ StringContext($parts: _*) }
159+
'{ StringContext($parts*) }
160160
}
161161
```
162162
The `Varargs` constructor just creates an `Expr[Seq[T]]` which we can efficiently splice as a varargs.
163-
In general, any sequence can be spliced with `$mySeq: _*` to splice it as a varargs.
163+
In general, any sequence can be spliced with `$mySeq*` to splice it as a varargs.
164164

165165
## Quoted patterns
166166
Quotes can also be used to check if an expression is equivalent to another or to deconstruct an expression into its parts.
@@ -352,7 +352,7 @@ Types represented with `Type[T]` can be matched on using the patten `case '[...]
352352
inline def mirrorFields[T]: List[String] = ${mirrorFieldsImpl[T]}
353353

354354
def mirrorFieldsImpl[T: Type](using Quotes): Expr[List[String]] =
355-
355+
356356
def rec[A : Type]: List[String] = Type.of[A] match
357357
case '[field *: fields] =>
358358
Type.show[field] :: rec[fields]
@@ -408,8 +408,8 @@ given FromExpr[Boolean] with {
408408

409409
given FromExpr[StringContext] with {
410410
def unapply(x: Expr[StringContext])(using Quotes): Option[StringContext] = x match {
411-
case '{ new StringContext(${Varargs(Exprs(args))}: _*) } => Some(StringContext(args: _*))
412-
case '{ StringContext(${Varargs(Exprs(args))}: _*) } => Some(StringContext(args: _*))
411+
case '{ new StringContext(${Varargs(Exprs(args))}*) } => Some(StringContext(args*))
412+
case '{ StringContext(${Varargs(Exprs(args))}*) } => Some(StringContext(args*))
413413
case _ => None
414414
}
415415
}

0 commit comments

Comments
 (0)
Please sign in to comment.