From e774a90b99a838de941385948ba95417fe23d4f9 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Mon, 26 Feb 2024 14:11:46 +0100 Subject: [PATCH] Update varargs syntax in quote pattern examples Issue found in https://github.com/lampepfl/dotty/issues/19709 --- _overviews/scala3-macros/tutorial/quotes.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/_overviews/scala3-macros/tutorial/quotes.md b/_overviews/scala3-macros/tutorial/quotes.md index b57f60c23..be3495895 100644 --- a/_overviews/scala3-macros/tutorial/quotes.md +++ b/_overviews/scala3-macros/tutorial/quotes.md @@ -156,11 +156,11 @@ given ToExpr[Boolean] with { given ToExpr[StringContext] with { def apply(stringContext: StringContext)(using Quotes) = val parts = Varargs(stringContext.parts.map(Expr(_))) - '{ StringContext($parts: _*) } + '{ StringContext($parts*) } } ``` The `Varargs` constructor just creates an `Expr[Seq[T]]` which we can efficiently splice as a varargs. -In general, any sequence can be spliced with `$mySeq: _*` to splice it as a varargs. +In general, any sequence can be spliced with `$mySeq*` to splice it as a varargs. ## Quoted patterns 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 '[...] inline def mirrorFields[T]: List[String] = ${mirrorFieldsImpl[T]} def mirrorFieldsImpl[T: Type](using Quotes): Expr[List[String]] = - + def rec[A : Type]: List[String] = Type.of[A] match case '[field *: fields] => Type.show[field] :: rec[fields] @@ -408,8 +408,8 @@ given FromExpr[Boolean] with { given FromExpr[StringContext] with { def unapply(x: Expr[StringContext])(using Quotes): Option[StringContext] = x match { - case '{ new StringContext(${Varargs(Exprs(args))}: _*) } => Some(StringContext(args: _*)) - case '{ StringContext(${Varargs(Exprs(args))}: _*) } => Some(StringContext(args: _*)) + case '{ new StringContext(${Varargs(Exprs(args))}*) } => Some(StringContext(args*)) + case '{ StringContext(${Varargs(Exprs(args))}*) } => Some(StringContext(args*)) case _ => None } }