diff --git a/community-build/community-projects/scalatest b/community-build/community-projects/scalatest index a482f76918ed..497f56bf1bb4 160000 --- a/community-build/community-projects/scalatest +++ b/community-build/community-projects/scalatest @@ -1 +1 @@ -Subproject commit a482f76918ed15e5da3b47aac7475597bcdd7f90 +Subproject commit 497f56bf1bb4f36689daef15da5efebca81f1867 diff --git a/community-build/community-projects/shapeless b/community-build/community-projects/shapeless index fb336168a597..1b5f31a5abce 160000 --- a/community-build/community-projects/shapeless +++ b/community-build/community-projects/shapeless @@ -1 +1 @@ -Subproject commit fb336168a597e159c4861434cf78d41bb76c630e +Subproject commit 1b5f31a5abce98e565f84a14a2f621427303dbff diff --git a/community-build/community-projects/utest b/community-build/community-projects/utest index 45181858a2e2..c1d9ec9c81bb 160000 --- a/community-build/community-projects/utest +++ b/community-build/community-projects/utest @@ -1 +1 @@ -Subproject commit 45181858a2e2518d7dd528ff300b4feb091f5444 +Subproject commit c1d9ec9c81bb33ea574150dc3813e38ab30f9955 diff --git a/compiler/src/dotty/tools/dotc/ast/Desugar.scala b/compiler/src/dotty/tools/dotc/ast/Desugar.scala index 256255060e8b..0b8cfa01f369 100644 --- a/compiler/src/dotty/tools/dotc/ast/Desugar.scala +++ b/compiler/src/dotty/tools/dotc/ast/Desugar.scala @@ -908,21 +908,26 @@ object desugar { /** Transforms * - * type $T >: Low <: Hi - * + * type t >: Low <: Hi * to * * @patternType type $T >: Low <: Hi * - * if the type is a type splice. + * if the type has a pattern variable name */ def quotedPatternTypeDef(tree: TypeDef)(using Context): TypeDef = { assert(ctx.mode.is(Mode.QuotedPattern)) - if (tree.name.startsWith("$") && !tree.isBackquoted) { + if tree.name.isVarPattern && !tree.isBackquoted then val patternTypeAnnot = New(ref(defn.InternalQuotedPatterns_patternTypeAnnot.typeRef)).withSpan(tree.span) val mods = tree.mods.withAddedAnnotation(patternTypeAnnot) tree.withMods(mods) - } + else if tree.name.startsWith("$") && !tree.isBackquoted then + report.error( + """Quoted pattern variable names starting with $ are not suported anymore. + |Use lower cases type pattern name instead. + |""".stripMargin, + tree.srcPos) + tree else tree } diff --git a/compiler/src/dotty/tools/dotc/core/NameKinds.scala b/compiler/src/dotty/tools/dotc/core/NameKinds.scala index 10e0fef7c2e1..a45973b2ccab 100644 --- a/compiler/src/dotty/tools/dotc/core/NameKinds.scala +++ b/compiler/src/dotty/tools/dotc/core/NameKinds.scala @@ -320,7 +320,7 @@ object NameKinds { val PatMatStdBinderName: UniqueNameKind = new UniqueNameKind("x") val PatMatAltsName: UniqueNameKind = new UniqueNameKind("matchAlts") val PatMatResultName: UniqueNameKind = new UniqueNameKind("matchResult") - val PatMatVarName: UniqueNameKind = new UniqueNameKind("ev$") + val PatMatGivenVarName: UniqueNameKind = new UniqueNameKind("$given") val LocalOptInlineLocalObj: UniqueNameKind = new UniqueNameKind("ilo") diff --git a/compiler/src/dotty/tools/dotc/core/NameOps.scala b/compiler/src/dotty/tools/dotc/core/NameOps.scala index 9db4a9018576..a84123361541 100644 --- a/compiler/src/dotty/tools/dotc/core/NameOps.scala +++ b/compiler/src/dotty/tools/dotc/core/NameOps.scala @@ -89,7 +89,7 @@ object NameOps { && (n != true_) && (n != null_)) } - } || name.is(PatMatVarName) + } || name.is(PatMatGivenVarName) def isOpAssignmentName: Boolean = name match { case raw.NE | raw.LE | raw.GE | EMPTY => diff --git a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala index b88d4a641f5e..051eabf6f5cd 100644 --- a/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala +++ b/compiler/src/dotty/tools/dotc/typer/QuotesAndSplices.scala @@ -11,7 +11,7 @@ import dotty.tools.dotc.core.Constants._ import dotty.tools.dotc.core.Contexts._ import dotty.tools.dotc.core.Decorators._ import dotty.tools.dotc.core.Flags._ -import dotty.tools.dotc.core.NameKinds.{UniqueName, PatMatVarName} +import dotty.tools.dotc.core.NameKinds.{UniqueName, PatMatGivenVarName} import dotty.tools.dotc.core.Names._ import dotty.tools.dotc.core.StagingContext._ import dotty.tools.dotc.core.StdNames._ @@ -37,7 +37,7 @@ trait QuotesAndSplices { import tpd._ - /** Translate `'{ t }` into `scala.quoted.Expr.apply(t)` and `'[T]` into `scala.quoted.Type.apply[T]` + /** Translate `'{ e }` into `scala.quoted.Expr.apply(e)` and `'[T]` into `scala.quoted.Type.apply[T]` * while tracking the quotation level in the context. */ def typedQuote(tree: untpd.Quote, pt: Type)(using Context): Tree = { @@ -83,7 +83,7 @@ trait QuotesAndSplices { def spliceOwner(ctx: Context): Symbol = if (ctx.mode.is(Mode.QuotedPattern)) spliceOwner(ctx.outer) else ctx.owner val pat = typedPattern(tree.expr, defn.QuotedExprClass.typeRef.appliedTo(pt))( - using spliceContext.retractMode(Mode.QuotedPattern).withOwner(spliceOwner(ctx))) + using spliceContext.retractMode(Mode.QuotedPattern).addMode(Mode.Pattern).withOwner(spliceOwner(ctx))) val baseType = pat.tpe.baseType(defn.QuotedExprClass) val argType = if baseType != NoType then baseType.argTypesHi.head else defn.NothingType ref(defn.InternalQuoted_exprSplice).appliedToType(argType).appliedTo(pat) @@ -158,25 +158,11 @@ trait QuotesAndSplices { } if ctx.mode.is(Mode.QuotedPattern) && level == 1 then - def spliceOwner(ctx: Context): Symbol = - if (ctx.mode.is(Mode.QuotedPattern)) spliceOwner(ctx.outer) else ctx.owner - val (name, expr) = tree.expr match { - case Ident(name) => - val nameOfSyntheticGiven = PatMatVarName.fresh() - (name.toTypeName, untpd.cpy.Ident(tree.expr)(nameOfSyntheticGiven)) - case expr => - report.error("expected a name binding", expr.srcPos) - ("$error".toTypeName, expr) - } - - val typeSymInfo = pt match - case pt: TypeBounds => pt - case _ => TypeBounds.empty - val typeSym = newSymbol(spliceOwner(ctx), name, EmptyFlags, typeSymInfo, NoSymbol, tree.expr.span) - typeSym.addAnnotation(Annotation(New(ref(defn.InternalQuotedPatterns_patternTypeAnnot.typeRef)).withSpan(tree.expr.span))) - val pat = typedPattern(expr, defn.QuotedTypeClass.typeRef.appliedTo(typeSym.typeRef))( - using spliceContext.retractMode(Mode.QuotedPattern).withOwner(spliceOwner(ctx))) - pat.select(tpnme.Underlying) + report.error( + """`$` for quote pattern varable is not supported anymore. + |Use lower cased variable name without the `$` instead.""".stripMargin, + tree.srcPos) + ref(defn.NothingType) else val tree1 = typedSelect(untpd.Select(tree.expr, tpnme.Underlying), pt)(using spliceContext).withSpan(tree.span) val msg = em"Consider using canonical type reference ${tree1.tpe} instead" @@ -185,6 +171,24 @@ trait QuotesAndSplices { tree1 } + /** Type a pattern variable name `t` in quote pattern as `${given t$giveni: Type[t @ _]}`. + * The resulting pattern is the split in `splitQuotePattern`. + */ + def typedQuotedTypeVar(tree: untpd.Ident, pt: Type)(using Context): Tree = + def spliceOwner(ctx: Context): Symbol = + if (ctx.mode.is(Mode.QuotedPattern)) spliceOwner(ctx.outer) else ctx.owner + val name = tree.name.toTypeName + val nameOfSyntheticGiven = PatMatGivenVarName.fresh(tree.name.toTermName) + val expr = untpd.cpy.Ident(tree)(nameOfSyntheticGiven) + val typeSymInfo = pt match + case pt: TypeBounds => pt + case _ => TypeBounds.empty + val typeSym = newSymbol(spliceOwner(ctx), name, EmptyFlags, typeSymInfo, NoSymbol, tree.span) + typeSym.addAnnotation(Annotation(New(ref(defn.InternalQuotedPatterns_patternTypeAnnot.typeRef)).withSpan(tree.span))) + val pat = typedPattern(expr, defn.QuotedTypeClass.typeRef.appliedTo(typeSym.typeRef))( + using spliceContext.retractMode(Mode.QuotedPattern).withOwner(spliceOwner(ctx))) + pat.select(tpnme.Underlying) + private def checkSpliceOutsideQuote(tree: untpd.Tree)(using Context): Unit = if (level == 0 && !ctx.owner.ownersIterator.exists(_.is(Inline))) report.error("Splice ${...} outside quotes '{...} or inline method", tree.srcPos) @@ -201,17 +205,17 @@ trait QuotesAndSplices { * * A quote pattern * ``` - * case '{ type ${given t: Type[$t @ _]}; ${ls: Expr[List[$t]]} } => ... + * case '{ type ${given t$giveni: Type[t @ _]}; ${ls: Expr[List[t]]} } => ... * ``` * will return * ``` * ( - * Map(<$t>: Symbol -> <$t @ _>: Bind), + * Map(: Symbol -> : Bind), * <'{ - * @scala.internal.Quoted.patternType type $t - * scala.internal.Quoted.patternHole[List[$t]] + * @scala.internal.Quoted.patternType type t + * scala.internal.Quoted.patternHole[List[t]] * }>: Tree, - * List(: Tree) + * List(: Tree) * ) * ``` */ @@ -278,7 +282,7 @@ trait QuotesAndSplices { tree case tdef: TypeDef => if tdef.symbol.hasAnnotation(defn.InternalQuotedPatterns_patternTypeAnnot) then - transformTypeBindingTypeDef(PatMatVarName.fresh(), tdef, typePatBuf) + transformTypeBindingTypeDef(PatMatGivenVarName.fresh(tdef.name.toTermName), tdef, typePatBuf) else if tdef.symbol.isClass then val kind = if tdef.symbol.is(Module) then "objects" else "classes" report.error("Implementation restriction: cannot match " + kind, tree.srcPos) @@ -358,21 +362,21 @@ trait QuotesAndSplices { * within the quotes become patterns again and typed accordingly. * * ``` - * case '{ ($ls: List[$t]) } => - * // `t` is of type `Type[T$1]` for some unknown T$1 - * // `t` is implicitly available - * // `l` is of type `Expr[List[T$1]]` + * case '{ ($ls: List[t]) } => + * // `t$giveni` is of type `Type[t]` for some unknown `t` + * // `t$giveni` is implicitly available + * // `ls` is of type `Expr[List[t]]` * '{ val h: $t = $ls.head } * ``` * - * For each type splice we will create a new type binding in the pattern match ($t @ _ in this case) - * and a corresponding type in the quoted pattern as a hole (@patternType type $t in this case). + * For each type splice we will create a new type binding in the pattern match (`t @ _` in this case) + * and a corresponding type in the quoted pattern as a hole (`@patternType type t` in this case). * All these generated types are inserted at the start of the quoted code. * * After typing the tree will resemble * * ``` - * case '{ type ${given t: Type[$t @ _]}; ${ls: Expr[List[$t]]} } => ... + * case '{ type ${given t$giveni: Type[t @ _]}; ${ls: Expr[List[t]]} } => ... * ``` * * Then the pattern is _split_ into the expression contained in the pattern replacing the splices by holes, @@ -380,16 +384,16 @@ trait QuotesAndSplices { * * ``` * case scala.internal.quoted.Expr.unapply[ - * Tuple1[$t @ _], // Type binging definition - * Tuple2[Type[$t], Expr[List[$t]]] // Typing the result of the pattern match + * Tuple1[t @ _], // Type binging definition + * Tuple2[Type[t], Expr[List[t]]] // Typing the result of the pattern match * ]( * Tuple2.unapply - * [Type[$t], Expr[List[$t]]] //Propagated from the tuple above - * (implicit t @ _, ls @ _: Expr[List[$t]]) // from the spliced patterns + * [Type[t], Expr[List[t]]] //Propagated from the tuple above + * (given t$giveni @ _, ls @ _: Expr[List[t]]) // from the spliced patterns * )( * '{ // Runtime quote Matcher.unapply uses to mach against. Expression directly inside the quoted pattern without the splices - * @scala.internal.Quoted.patternType type $t - * scala.internal.Quoted.patternHole[List[$t]] + * @scala.internal.Quoted.patternType type t + * scala.internal.Quoted.patternHole[List[t]] * }, * true, // If there is at least one type splice. Used to instantiate the context with or without GADT constraints * x$2 // tasty.Reflection instance @@ -409,7 +413,7 @@ trait QuotesAndSplices { case _ => defn.AnyType } val quoted0 = desugar.quotedPattern(quoted, untpd.TypedSplice(TypeTree(quotedPt))) - val quoteCtx = quoteContext.addMode(Mode.QuotedPattern) + val quoteCtx = quoteContext.addMode(Mode.QuotedPattern).retractMode(Mode.Pattern) val quoted1 = if quoted.isType then typedType(quoted0, WildcardType)(using quoteCtx) else typedExpr(quoted0, WildcardType)(using quoteCtx) diff --git a/compiler/src/dotty/tools/dotc/typer/Typer.scala b/compiler/src/dotty/tools/dotc/typer/Typer.scala index 182725c11bd2..e61a7f438102 100644 --- a/compiler/src/dotty/tools/dotc/typer/Typer.scala +++ b/compiler/src/dotty/tools/dotc/typer/Typer.scala @@ -431,12 +431,16 @@ class Typer extends Namer val name = tree.name def kind = if (name.isTermName) "" else "type " typr.println(s"typed ident $kind$name in ${ctx.owner}") - if (ctx.mode is Mode.Pattern) { - if (name == nme.WILDCARD) + if ctx.mode.is(Mode.Pattern) then + if name == nme.WILDCARD then return tree.withType(pt) - if (untpd.isVarPattern(tree) && name.isTermName) + if untpd.isVarPattern(tree) && name.isTermName then return typed(desugar.patternVar(tree), pt) - } + else if ctx.mode.is(Mode.QuotedPattern) then + if untpd.isVarPattern(tree) && name.isTypeName then + return typedQuotedTypeVar(tree, pt) + end if + // Shortcut for the root package, this is not just a performance // optimization, it also avoids forcing imports thus potentially avoiding // cyclic references. diff --git a/docs/docs/reference/metaprogramming/macros.md b/docs/docs/reference/metaprogramming/macros.md index 481699c95ad5..6ece61300ec3 100644 --- a/docs/docs/reference/metaprogramming/macros.md +++ b/docs/docs/reference/metaprogramming/macros.md @@ -703,11 +703,11 @@ Sometimes it is necessary to get a more precise type for an expression. This can ```scala def f(exp: Expr[Any])(using QuoteContext) = expr match - case '{ $x: $T } => - // If the pattern match succeeds, then there is some type `T` such that - // - `x` is bound to a variable of type `Expr[T]` - // - `T` is bound to a new type T and a given instance `Type[T]` is provided for it - // That is, we have `x: Expr[T]` and `given Type[T]`, for some (unknown) type `T`. + case '{ $x: t } => + // If the pattern match succeeds, then there is some type `t` such that + // - `x` is bound to a variable of type `Expr[t]` + // - `t` is bound to a new type `t` and a given instance `Type[t]` is provided for it + // That is, we have `x: Expr[t]` and `given Type[t]`, for some (unknown) type `t`. ``` This might be used to then perform an implicit search as in: @@ -720,8 +720,8 @@ private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using argsExpr match { case Varargs(argExprs) => val argShowedExprs = argExprs.map { - case '{ $arg: $T } => - Expr.summon[Show[T]] match { + case '{ $arg: t } => + Expr.summon[Show[t]] match { case Some(showExpr) => '{ $showExpr.show($arg) } case None => Reporting.error(s"could not find implicit for ${showTp.show}", arg); '{???} } diff --git a/library/src-bootstrapped/scala/quoted/Expr.scala b/library/src-bootstrapped/scala/quoted/Expr.scala index c545baffb253..31ba66b5f2d3 100644 --- a/library/src-bootstrapped/scala/quoted/Expr.scala +++ b/library/src-bootstrapped/scala/quoted/Expr.scala @@ -124,49 +124,49 @@ object Expr { seq match { case Seq() => '{ Tuple() } - case Seq('{ $x1: $t1 }) => + case Seq('{ $x1: t1 }) => '{ Tuple1($x1) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }) => '{ Tuple2($x1, $x2) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }) => '{ Tuple3($x1, $x2, $x3) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }) => '{ Tuple4($x1, $x2, $x3, $x4) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }) => '{ Tuple5($x1, $x2, $x3, $x4, $x5) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }) => '{ Tuple6($x1, $x2, $x3, $x4, $x5, $x6) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }) => '{ Tuple7($x1, $x2, $x3, $x4, $x5, $x6, $x7) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }) => '{ Tuple8($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }) => '{ Tuple9($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }) => '{ Tuple10($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }) => '{ Tuple11($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }) => '{ Tuple12($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }, '{ $x13: $t13 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }) => '{ Tuple13($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }, '{ $x13: $t13 }, '{ $x14: $t14 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }) => '{ Tuple14($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }, '{ $x13: $t13 }, '{ $x14: $t14 }, '{ $x15: $t15 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }) => '{ Tuple15($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }, '{ $x13: $t13 }, '{ $x14: $t14 }, '{ $x15: $t15 }, '{ $x16: $t16 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }) => '{ Tuple16($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }, '{ $x13: $t13 }, '{ $x14: $t14 }, '{ $x15: $t15 }, '{ $x16: $t16 }, '{ $x17: $t17 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }) => '{ Tuple17($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }, '{ $x13: $t13 }, '{ $x14: $t14 }, '{ $x15: $t15 }, '{ $x16: $t16 }, '{ $x17: $t17 }, '{ $x18: $t18 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }, '{ $x18: t18 }) => '{ Tuple18($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }, '{ $x13: $t13 }, '{ $x14: $t14 }, '{ $x15: $t15 }, '{ $x16: $t16 }, '{ $x17: $t17 }, '{ $x18: $t18 }, '{ $x19: $t19 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }, '{ $x18: t18 }, '{ $x19: t19 }) => '{ Tuple19($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }, '{ $x13: $t13 }, '{ $x14: $t14 }, '{ $x15: $t15 }, '{ $x16: $t16 }, '{ $x17: $t17 }, '{ $x18: $t18 }, '{ $x19: $t19 }, '{ $x20: $t20 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }, '{ $x18: t18 }, '{ $x19: t19 }, '{ $x20: t20 }) => '{ Tuple20($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }, '{ $x13: $t13 }, '{ $x14: $t14 }, '{ $x15: $t15 }, '{ $x16: $t16 }, '{ $x17: $t17 }, '{ $x18: $t18 }, '{ $x19: $t19 }, '{ $x20: $t20 }, '{ $x21: $t21 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }, '{ $x18: t18 }, '{ $x19: t19 }, '{ $x20: t20 }, '{ $x21: t21 }) => '{ Tuple21($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21) } - case Seq('{ $x1: $t1 }, '{ $x2: $t2 }, '{ $x3: $t3 }, '{ $x4: $t4 }, '{ $x5: $t5 }, '{ $x6: $t6 }, '{ $x7: $t7 }, '{ $x8: $t8 }, '{ $x9: $t9 }, '{ $x10: $t10 }, '{ $x11: $t11 }, '{ $x12: $t12 }, '{ $x13: $t13 }, '{ $x14: $t14 }, '{ $x15: $t15 }, '{ $x16: $t16 }, '{ $x17: $t17 }, '{ $x18: $t18 }, '{ $x19: $t19 }, '{ $x20: $t20 }, '{ $x21: $t21 }, '{ $x22: $t22 }) => + case Seq('{ $x1: t1 }, '{ $x2: t2 }, '{ $x3: t3 }, '{ $x4: t4 }, '{ $x5: t5 }, '{ $x6: t6 }, '{ $x7: t7 }, '{ $x8: t8 }, '{ $x9: t9 }, '{ $x10: t10 }, '{ $x11: t11 }, '{ $x12: t12 }, '{ $x13: t13 }, '{ $x14: t14 }, '{ $x15: t15 }, '{ $x16: t16 }, '{ $x17: t17 }, '{ $x18: t18 }, '{ $x19: t19 }, '{ $x20: t20 }, '{ $x21: t21 }, '{ $x22: t22 }) => '{ Tuple22($x1, $x2, $x3, $x4, $x5, $x6, $x7, $x8, $x9, $x10, $x11, $x12, $x13, $x14, $x15, $x16, $x17, $x18, $x19, $x20, $x21, $x22) } case _ => '{ Tuple.fromIArray(IArray(${Varargs(seq)}: _*)) } diff --git a/tests/neg-macros/quotedPatterns-5.scala b/tests/neg-macros/quotedPatterns-5.scala index 3638b21e4724..490d34a35981 100644 --- a/tests/neg-macros/quotedPatterns-5.scala +++ b/tests/neg-macros/quotedPatterns-5.scala @@ -1,10 +1,10 @@ import scala.quoted._ object Test { def test(x: quoted.Expr[Int])(using QuoteContext): Unit = x match { - case '{ type $T; 4 } => Type[T] - case '{ type $T; poly[$T]($x); 4 } => // error: duplicate pattern variable: T - case '{ type `$T`; poly[`$T`]($x); 4 } => - Type[T] // error + case '{ type t; 4 } => Type[t] + case '{ type t; poly[t]($x); 4 } => // error: duplicate pattern variable: t + case '{ type `t`; poly[`t`]($x); 4 } => + Type[t] // error case _ => } diff --git a/tests/neg-macros/quotedPatterns-6.scala b/tests/neg-macros/quotedPatterns-6.scala index 002b1d47a7b0..ba4698213b37 100644 --- a/tests/neg-macros/quotedPatterns-6.scala +++ b/tests/neg-macros/quotedPatterns-6.scala @@ -2,7 +2,7 @@ import scala.quoted._ object Test { def test(x: quoted.Expr[Int])(using QuoteContext) = x match { case '{ poly[${Foo(t)}]($x); 4 } => ??? // error - case '{ type $t; poly[${Foo(y: Type[`$t`])}]($x); 4 } => ??? // error + case '{ type t; poly[${Foo(y: Type[`t`])}]($x); 4 } => ??? // error case _ => } diff --git a/tests/pos-macros/i10050.scala b/tests/pos-macros/i10050.scala new file mode 100644 index 000000000000..2fec1bbb123e --- /dev/null +++ b/tests/pos-macros/i10050.scala @@ -0,0 +1,29 @@ +import scala.quoted._ + +def test[T: Type](x: Expr[Any])(using QuoteContext): Unit = + + x match + case '{ $x: T } => // match using outer `T` + '{ val y: T = $x; } + + x match + case '{ $x: t } => // match any `t` and bind it as a type variable + '{ val y: t = $x; } // use `t` provided by previous match + + x match + case '{ $x: List[t] } => // match any `t` and bind it as a type variable + '{ val y: List[t] = $x; } // use `t` provided by previous match + + x match + case '{ $x: t } => // match any `t` and bind it as a type variable + x match + case '{ $x: `t` } => // match using outer `t` provided by previous match + '{ val y: t = $x; } + + x match + case '{ type t; $x: `t` } => // match any `t` and bind it as a type variable + '{ val y: t = $x; } // use `t` provided by previous match + + Type[T] match + case '[List[u]] => Type[u] + case '[u] => Type[u] diff --git a/tests/pos-macros/i6997c.scala b/tests/pos-macros/i6997c.scala index 2d3a56bfb496..1bf1858330c9 100644 --- a/tests/pos-macros/i6997c.scala +++ b/tests/pos-macros/i6997c.scala @@ -6,9 +6,9 @@ inline def mcr(x: => Any): Any = ${mcrImpl('x)} def mcrImpl(body: Expr[Any])(using ctx: QuoteContext): Expr[Any] = body match - case '{$x: $T} => + case '{$x: t} => '{ - val tmp: T = $x + val tmp: t = $x println(tmp) tmp } diff --git a/tests/pos-macros/i7264.scala b/tests/pos-macros/i7264.scala index a4f2c7722be2..b2ebe9332ccb 100644 --- a/tests/pos-macros/i7264.scala +++ b/tests/pos-macros/i7264.scala @@ -1,7 +1,7 @@ import scala.quoted._ class Foo { def f[T2](t: Type[T2])(using QuoteContext) = t match { - case '[ *:[Int, $T] ] => - Type[ *:[Int, T] ] + case '[ *:[Int, t2] ] => + Type[ *:[Int, t2] ] } -} \ No newline at end of file +} diff --git a/tests/pos-macros/i7264b.scala b/tests/pos-macros/i7264b.scala index ab26562b94ed..057e9433d4b9 100644 --- a/tests/pos-macros/i7264b.scala +++ b/tests/pos-macros/i7264b.scala @@ -1,7 +1,7 @@ import scala.quoted._ class Foo { def f[T2: Type](e: Expr[T2])(using QuoteContext) = e match { - case '{ $x: *:[Int, $t] } => + case '{ $x: *:[Int, t] } => Type[ *:[Int, t] ] } } diff --git a/tests/pos-macros/i7264c.scala b/tests/pos-macros/i7264c.scala index a49026549be1..107b5e5df2b6 100644 --- a/tests/pos-macros/i7264c.scala +++ b/tests/pos-macros/i7264c.scala @@ -1,9 +1,9 @@ import scala.quoted._ class Foo { def f[T2: Type](e: Expr[T2])(using QuoteContext) = e match { - case '{ $x: $T0 } => - Type[T0] match - case '[ *:[Int, $T] ] => - Type[ *:[Int, T] ] + case '{ $x: t0 } => + Type[t0] match + case '[ *:[Int, t] ] => + Type[ *:[Int, t] ] } } diff --git a/tests/pos-macros/i8100.scala b/tests/pos-macros/i8100.scala index 04c7aa4c0ebe..b9517d9ccef0 100644 --- a/tests/pos-macros/i8100.scala +++ b/tests/pos-macros/i8100.scala @@ -6,7 +6,7 @@ class M { def f[T: Type](using QuoteContext) = Expr.summon[M] match - case Some('{ $mm : $tt }) => + case Some('{ $mm : tt }) => '{ val m = $mm type ME = m.E diff --git a/tests/pos-macros/i9465.scala b/tests/pos-macros/i9465.scala index 574429af600c..9c59f08b2ffb 100644 --- a/tests/pos-macros/i9465.scala +++ b/tests/pos-macros/i9465.scala @@ -7,6 +7,6 @@ trait Coll[A] { object QuoteTest { def compile(expr: Expr[Any])(using QuoteContext): Expr[Any] = expr match { - case '{ (??? : Coll[$y]).map[$b] } => ??? + case '{ (??? : Coll[y]).map[b] } => ??? } } diff --git a/tests/pos-macros/quote-matching-implicit-types.scala b/tests/pos-macros/quote-matching-implicit-types.scala index f7c2edf88c4d..cf4e781acbaf 100644 --- a/tests/pos-macros/quote-matching-implicit-types.scala +++ b/tests/pos-macros/quote-matching-implicit-types.scala @@ -3,10 +3,10 @@ import scala.quoted._ object Foo { def f(e: Expr[Any])(using QuoteContext): Unit = e match { - case '{ foo[$t]($x) } => bar(x) - case '{ foo[$t]($x) } if bar(x) => () - case '{ foo[$t]($x) } => '{ foo($x) } - case '{ foo[$t]($x) } if bar[Any]('{ foo($x) }) => () + case '{ foo[t]($x) } => bar(x) + case '{ foo[t]($x) } if bar(x) => () + case '{ foo[t]($x) } => '{ foo($x) } + case '{ foo[t]($x) } if bar[Any]('{ foo($x) }) => () } def foo[T](t: T): Unit = () diff --git a/tests/pos-macros/quotedPatterns.scala b/tests/pos-macros/quotedPatterns.scala index 45d9675aace8..92e1822de5a2 100644 --- a/tests/pos-macros/quotedPatterns.scala +++ b/tests/pos-macros/quotedPatterns.scala @@ -25,10 +25,10 @@ object Test { z case '{ def ff[T](i: T): Int = $z; 2 } => z - case '{ poly[$t]($x); 4 } => ??? - case '{ type $X; poly[`$X`]($x); 4 } => ??? - case '{ type $T; val x: `$T` = $a; val y: `$T` = x; 1 } => ??? - case '{ type $t <: AnyRef; val x: `$t` = $a; val y: `$t` = x; 1 } => ??? + case '{ poly[t]($x); 4 } => ??? + case '{ type x; poly[`x`]($x); 4 } => ??? + case '{ type t; val x: `t` = $a; val y: `t` = x; 1 } => ??? + case '{ type t <: AnyRef; val x: `t` = $a; val y: `t` = x; 1 } => ??? case _ => '{1} } diff --git a/tests/pos-macros/tasty-constant-type/Macro_1.scala b/tests/pos-macros/tasty-constant-type/Macro_1.scala index 9bd81775d148..4f19ae998264 100644 --- a/tests/pos-macros/tasty-constant-type/Macro_1.scala +++ b/tests/pos-macros/tasty-constant-type/Macro_1.scala @@ -13,6 +13,6 @@ object Macro { val ConstantType(Constant.Int(v2)) = TypeRepr.of[B] Literal(Constant.Int(v1 + v2)).tpe.seal match - case '[$T] => '{ null: AddInt[A, B] { type Out = T } } + case '[t] => '{ null: AddInt[A, B] { type Out = t } } } } diff --git a/tests/run-macros/flops-rewrite-3/Macro_1.scala b/tests/run-macros/flops-rewrite-3/Macro_1.scala index 4df32b6f8684..82198863f8f2 100644 --- a/tests/run-macros/flops-rewrite-3/Macro_1.scala +++ b/tests/run-macros/flops-rewrite-3/Macro_1.scala @@ -59,7 +59,7 @@ class CheckedTransformation(transform: PartialFunction[Expr[Any], Expr[Any]]) ex def apply[T: Type](e: Expr[T])(using QuoteContext): Expr[T] = { transform.applyOrElse(e, identity) match { case '{ $e2: T } => e2 - case '{ $e2: $T2 } => + case '{ $e2: t } => throw new Exception( s"""Transformed |${e.show} @@ -69,7 +69,7 @@ class CheckedTransformation(transform: PartialFunction[Expr[Any], Expr[Any]]) ex |Expected type to be |${Type.show[T]} |but was - |${Type.show[T2]} + |${Type.show[t]} """.stripMargin) } } diff --git a/tests/run-macros/flops-rewrite/Macro_1.scala b/tests/run-macros/flops-rewrite/Macro_1.scala index e4d0f5a7f3a1..7c71cf503ab3 100644 --- a/tests/run-macros/flops-rewrite/Macro_1.scala +++ b/tests/run-macros/flops-rewrite/Macro_1.scala @@ -5,10 +5,10 @@ inline def rewrite[T](inline x: T): T = ${ rewriteMacro('x) } private def rewriteMacro[T: Type](x: Expr[T])(using QuoteContext): Expr[T] = { val rewriter = Rewriter( postTransform = { - case '{ Nil.map[$t]($f) } => '{ Nil } + case '{ Nil.map[t]($f) } => '{ Nil } case '{ Nil.filter($f) } => '{ Nil } - case '{ Nil.++[$t]($xs) } => xs - case '{ ($xs: List[$t]).++(Nil) } => xs + case '{ Nil.++[t]($xs) } => xs + case '{ ($xs: List[t]).++(Nil) } => xs case x => x } ) @@ -40,7 +40,7 @@ private class Rewriter(preTransform: Expr[Any] => Expr[Any], postTransform: Expr private def checkedTransform[T: Type](e: Expr[T], transform: Expr[T] => Expr[Any])(using QuoteContext): Expr[T] = { transform(e) match { case '{ $x: T } => x - case '{ $x: $t } => throw new Exception( + case '{ $x: t } => throw new Exception( s"""Transformed |${e.show} |into diff --git a/tests/run-macros/i7987/Macros_1.scala b/tests/run-macros/i7987/Macros_1.scala index 7e69475de45e..f6017ee597f9 100644 --- a/tests/run-macros/i7987/Macros_1.scala +++ b/tests/run-macros/i7987/Macros_1.scala @@ -7,6 +7,6 @@ object Macros { def macroImpl[T]()(using qctx: QuoteContext): Expr[String] = { Expr.summon[Mirror.Of[Some[Int]]] match - case Some('{ $_ : $T }) => Expr(Type.show[T]) + case Some('{ $_ : t }) => Expr(Type.show[t]) } } diff --git a/tests/run-macros/i8007/Macro_1.scala b/tests/run-macros/i8007/Macro_1.scala index ba6f9b4018ad..4991e1d994a8 100644 --- a/tests/run-macros/i8007/Macro_1.scala +++ b/tests/run-macros/i8007/Macro_1.scala @@ -6,7 +6,7 @@ object Macro1 { def mirrorFields[T: Type](using qctx: QuoteContext): List[String] = Type[T] match { - case '[$Field *: $Fields] => Type.show[Field] :: mirrorFields[Fields] + case '[field *: fields] => Type.show[field] :: mirrorFields[fields] case '[EmptyTuple] => Nil } @@ -22,8 +22,8 @@ object Macro1 { val mirrorTpe = Type[Mirror.Of[T]] Expr.summon(using mirrorTpe).get match { - case '{ $m: Mirror.ProductOf[T]{ type MirroredElemLabels = $Elems } } => { - Expr(mirrorFields[Elems]) + case '{ $m: Mirror.ProductOf[T]{ type MirroredElemLabels = elems } } => { + Expr(mirrorFields[elems]) } } } diff --git a/tests/run-macros/i8007/Macro_2.scala b/tests/run-macros/i8007/Macro_2.scala index 31b8a107f13c..0c75fb165aab 100644 --- a/tests/run-macros/i8007/Macro_2.scala +++ b/tests/run-macros/i8007/Macro_2.scala @@ -6,7 +6,7 @@ object Macro2 { def mirrorFields[T](using t: Type[T])(using qctx: QuoteContext): List[String] = t match { - case '[$Field *: $Fields] => Type.show[Field].substring(1, Type.show[Field].length-1) :: mirrorFields[Fields] + case '[field *: fields] => Type.show[field].substring(1, Type.show[field].length-1) :: mirrorFields[fields] case '[EmptyTuple] => Nil } @@ -24,8 +24,8 @@ object Macro2 { import qctx.reflect._ val fields = ev match { - case '{ $m: Mirror.ProductOf[T] { type MirroredElemLabels = $Labels } } => - mirrorFields[Labels] + case '{ $m: Mirror.ProductOf[T] { type MirroredElemLabels = labels } } => + mirrorFields[labels] } val body: Expr[T] => Expr[String] = elem => diff --git a/tests/run-macros/i8007/Macro_3.scala b/tests/run-macros/i8007/Macro_3.scala index 19c389ce63a3..34cb9c7e3545 100644 --- a/tests/run-macros/i8007/Macro_3.scala +++ b/tests/run-macros/i8007/Macro_3.scala @@ -26,9 +26,9 @@ object Eq { } def summonAll[T](using t: Type[T])(using qctx: QuoteContext): List[Expr[Eq[_]]] = t match { - case '[String *: $Tpes] => '{ summon[Eq[String]] } :: summonAll[Tpes] - case '[Int *: $Tpes] => '{ summon[Eq[Int]] } :: summonAll[Tpes] - case '[$Tpe *: $Tpes] => derived[Tpe] :: summonAll[Tpes] + case '[String *: tpes] => '{ summon[Eq[String]] } :: summonAll[tpes] + case '[Int *: tpes] => '{ summon[Eq[Int]] } :: summonAll[tpes] + case '[tpe *: tpes] => derived[tpe] :: summonAll[tpes] case '[EmptyTuple] => Nil } @@ -38,8 +38,8 @@ object Eq { val ev: Expr[Mirror.Of[T]] = Expr.summon(using Type[Mirror.Of[T]]).get ev match { - case '{ $m: Mirror.ProductOf[T] { type MirroredElemTypes = $ElementTypes }} => - val elemInstances = summonAll[ElementTypes] + case '{ $m: Mirror.ProductOf[T] { type MirroredElemTypes = elementTypes }} => + val elemInstances = summonAll[elementTypes] val eqProductBody: (Expr[T], Expr[T]) => Expr[Boolean] = (x, y) => { elemInstances.zipWithIndex.foldLeft(Expr(true: Boolean)) { case (acc, (elem, index)) => @@ -53,8 +53,8 @@ object Eq { eqProduct((x: T, y: T) => ${eqProductBody('x, 'y)}) } - case '{ $m: Mirror.SumOf[T] { type MirroredElemTypes = $ElementTypes }} => - val elemInstances = summonAll[ElementTypes] + case '{ $m: Mirror.SumOf[T] { type MirroredElemTypes = elementTypes }} => + val elemInstances = summonAll[elementTypes] val eqSumBody: (Expr[T], Expr[T]) => Expr[Boolean] = (x, y) => { val ordx = '{ $m.ordinal($x) } val ordy = '{ $m.ordinal($y) } diff --git a/tests/run-macros/i8746/Macro_1.scala b/tests/run-macros/i8746/Macro_1.scala index 66902e3203cf..de6a895d4c74 100644 --- a/tests/run-macros/i8746/Macro_1.scala +++ b/tests/run-macros/i8746/Macro_1.scala @@ -4,7 +4,7 @@ object Macro { inline def mac(): String = ${ macImpl() } def macImpl()(using qctx: QuoteContext): Expr[String] = '{(x: String) => "anything"} match - case '{ (in: String) => ($out: $tpe2) } => Expr(out.toString) + case '{ (in: String) => ($out: tpe2) } => Expr(out.toString) case _ => ??? } diff --git a/tests/run-macros/i8746b/Macro_1.scala b/tests/run-macros/i8746b/Macro_1.scala index 4b1332f04a6b..cc973c24a27c 100644 --- a/tests/run-macros/i8746b/Macro_1.scala +++ b/tests/run-macros/i8746b/Macro_1.scala @@ -5,7 +5,7 @@ object Macro { inline def mac(inline tree: Any): String = ${ macImpl('tree) } def macImpl(tree: Expr[Any])(using qctx: QuoteContext): Expr[String] = { tree match { - case '{ (in: $tpe1) => ($out: $tpe2) } => Expr(out.toString) + case '{ (in: tpe1) => ($out: tpe2) } => Expr(out.toString) case _ => Expr("not matched") } } diff --git a/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala b/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala index bf1591ab6c2f..d5a8ae242423 100644 --- a/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala +++ b/tests/run-macros/quote-matcher-symantics-3/quoted_1.scala @@ -18,7 +18,7 @@ object Macros { object FromEnv { def unapply[T](e: Expr[Any])(using env: Env): Option[Expr[R[T]]] = e match - case '{envVar[$_](${Const(id)})} => + case '{envVar[t](${Const(id)})} => env.get(id).asInstanceOf[Option[Expr[R[T]]]] // We can only add binds that have the same type as the refs case _ => None @@ -37,11 +37,11 @@ object Macros { case '{ ($x: Int) <= ($y: Int) } => '{ $sym.leq(${lift(x)}, ${lift(y)}).asInstanceOf[R[T]] } - case '{ ${f}($arg: $A): $B } => - '{ $sym.app[A, B](${lift(f)}, ${lift(arg)}).asInstanceOf[R[T]] } + case '{ ${f}($arg: a): b } => + '{ $sym.app[a, b](${lift(f)}, ${lift(arg)}).asInstanceOf[R[T]] } - case '{ (if ($cond) $thenp else $elsep): $A } => - '{ $sym.ifThenElse[A](${lift(cond)}, ${lift(thenp)}, ${lift(elsep)}) }.asInstanceOf[Expr[R[T]]] + case '{ (if ($cond) $thenp else $elsep): a } => + '{ $sym.ifThenElse[a](${lift(cond)}, ${lift(thenp)}, ${lift(elsep)}) }.asInstanceOf[Expr[R[T]]] case '{ (x0: Int) => $bodyFn(x0): Any } => val (i, nEnvVar) = freshEnvVar[Int]() @@ -58,8 +58,8 @@ object Macros { val body2 = UnsafeExpr.open(bodyFn) { (body1, close) => close(body1)(nEnvVar) } '{ $sym.lam((x: R[Int => Int]) => ${given Env = envWith(i, 'x)(using env); lift(body2)}).asInstanceOf[R[T]] } - case '{ Symantics.fix[$A, $B]($f) } => - '{ $sym.fix[A, B]((x: R[A => B]) => $sym.app(${lift(f)}, x)).asInstanceOf[R[T]] } + case '{ Symantics.fix[a, b]($f) } => + '{ $sym.fix[a, b]((x: R[a => b]) => $sym.app(${lift(f)}, x)).asInstanceOf[R[T]] } case FromEnv(expr) => expr.asInstanceOf[Expr[R[T]]] diff --git a/tests/run-macros/quote-matcher-type-bind/Macro_1.scala b/tests/run-macros/quote-matcher-type-bind/Macro_1.scala index 5d52ff8620b5..2311529c0c3f 100644 --- a/tests/run-macros/quote-matcher-type-bind/Macro_1.scala +++ b/tests/run-macros/quote-matcher-type-bind/Macro_1.scala @@ -7,8 +7,8 @@ object Macros { private def impl(x: Expr[Unit])(using QuoteContext): Expr[Unit] = { x match { - case '{ DSL.f[$T]($x) } => '{ DSL.g[T]($x) } - case '{ DSL.g[$T]($x) } => '{ DSL.f[T]($x) } + case '{ DSL.f[t]($x) } => '{ DSL.g[t]($x) } + case '{ DSL.g[t]($x) } => '{ DSL.f[t]($x) } case _ => x } } diff --git a/tests/run-macros/quote-matching-optimize-1/Macro_1.scala b/tests/run-macros/quote-matching-optimize-1/Macro_1.scala index d6a5e64f409a..8bcdfcbd41c1 100644 --- a/tests/run-macros/quote-matching-optimize-1/Macro_1.scala +++ b/tests/run-macros/quote-matching-optimize-1/Macro_1.scala @@ -7,13 +7,13 @@ object Macro { def impl[T: Type](x: Expr[T])(using QuoteContext): Expr[Any] = { def optimize(x: Expr[Any]): Expr[Any] = x match { - case '{ type $t; ($ls: List[`$t`]).filter($f).filter($g) } => + case '{ type t; ($ls: List[`t`]).filter($f).filter($g) } => optimize('{ $ls.filter(x => ${Expr.betaReduce('{$f(x)})} && ${Expr.betaReduce('{$g(x)})}) }) - case '{ type $t; type $u; type $v; ($ls: List[`$t`]).map[`$u`]($f).map[`$v`]($g) } => + case '{ type t; type u; type v; ($ls: List[`t`]).map[`u`]($f).map[`v`]($g) } => optimize('{ $ls.map(x => ${Expr.betaReduce('{$g(${Expr.betaReduce('{$f(x)})})})}) }) - case '{ type $t; ($ls: List[`$t`]).filter($f).foreach[Unit]($g) } => + case '{ type t; ($ls: List[`t`]).filter($f).foreach[Unit]($g) } => optimize('{ $ls.foreach(x => if (${Expr.betaReduce('{$f(x)})}) ${Expr.betaReduce('{$g(x)})} else ()) }) case _ => x diff --git a/tests/run-macros/quote-matching-optimize-2/Macro_1.scala b/tests/run-macros/quote-matching-optimize-2/Macro_1.scala index f8b869c2e974..467138e82374 100644 --- a/tests/run-macros/quote-matching-optimize-2/Macro_1.scala +++ b/tests/run-macros/quote-matching-optimize-2/Macro_1.scala @@ -7,13 +7,13 @@ object Macro { def impl[T: Type](x: Expr[T])(using QuoteContext): Expr[Any] = { def optimize(x: Expr[Any]): Expr[Any] = x match { - case '{ ($ls: List[$t]).filter($f).filter($g) } => + case '{ ($ls: List[t]).filter($f).filter($g) } => optimize('{ $ls.filter(x => ${Expr.betaReduce('{$f(x)})} && ${Expr.betaReduce('{$g(x)})}) }) - case '{ type $u; type $v; ($ls: List[$t]).map[`$u`]($f).map[`$v`]($g) } => + case '{ type u; type v; ($ls: List[t]).map[`u`]($f).map[`v`]($g) } => optimize('{ $ls.map(x => ${Expr.betaReduce('{$g(${Expr.betaReduce('{$f(x)})})})}) }) - case '{ ($ls: List[$t]).filter($f).foreach[$u]($g) } => + case '{ ($ls: List[t]).filter($f).foreach[u]($g) } => optimize('{ $ls.foreach[Any](x => if (${Expr.betaReduce('{$f(x)})}) ${Expr.betaReduce('{$g(x)})} else ()) }) case _ => x diff --git a/tests/run-macros/quote-matching-optimize-3/Macro_1.scala b/tests/run-macros/quote-matching-optimize-3/Macro_1.scala index 4628d8019d48..c414011fc8bb 100644 --- a/tests/run-macros/quote-matching-optimize-3/Macro_1.scala +++ b/tests/run-macros/quote-matching-optimize-3/Macro_1.scala @@ -7,13 +7,13 @@ object Macro { def impl[T: Type](x: Expr[T])(using QuoteContext): Expr[Any] = { def optimize(x: Expr[Any]): Expr[Any] = x match { - case '{ ($ls: List[$t]).filter($f).filter($g) } => + case '{ ($ls: List[t]).filter($f).filter($g) } => optimize('{ $ls.filter(x => $f(x) && $g(x)) }) - case '{ type $uu; type $vv; ($ls: List[$tt]).map[`$uu`]($f).map[String]($g) } => + case '{ type uu; type vv; ($ls: List[tt]).map[`uu`]($f).map[String]($g) } => optimize('{ $ls.map(x => $g($f(x))) }) - case '{ ($ls: List[$t]).filter($f).foreach[$u]($g) } => + case '{ ($ls: List[t]).filter($f).foreach[u]($g) } => optimize('{ $ls.foreach[Any](x => if ($f(x)) $g(x) else ()) }) case _ => x diff --git a/tests/run-macros/quote-type-matcher-2/quoted_1.scala b/tests/run-macros/quote-type-matcher-2/quoted_1.scala index c034ffc19c70..6d132c8d06a6 100644 --- a/tests/run-macros/quote-type-matcher-2/quoted_1.scala +++ b/tests/run-macros/quote-type-matcher-2/quoted_1.scala @@ -7,9 +7,9 @@ object Macros { private def matchesExpr[A](using tp: Type[A])(using QuoteContext): Expr[String] = { def lift[T](using tp: Type[T]): String = tp match { case '[Int] => "%Int%" - case '[List[$T]] => s"%List[${lift[T]}]%" - case '[Option[$T]] => s"%Option[${lift[T]}]%" - case '[Function1[$T, $U]] => s"%${lift[T]} => ${lift[U]}%" + case '[List[t]] => s"%List[${lift[t]}]%" + case '[Option[t]] => s"%Option[${lift[t]}]%" + case '[Function1[t, u]] => s"%${lift[t]} => ${lift[u]}%" case _ => Type.show[T] } Expr(lift[A]) diff --git a/tests/run-macros/refined-selectable-macro/Macro_1.scala b/tests/run-macros/refined-selectable-macro/Macro_1.scala index 3dbc1020b16e..34faf285910d 100644 --- a/tests/run-macros/refined-selectable-macro/Macro_1.scala +++ b/tests/run-macros/refined-selectable-macro/Macro_1.scala @@ -38,8 +38,8 @@ object Macro { def tupleElem(name: String, info: TypeRepr): Expr[Any] = { val nameExpr = Expr(name) - info.seal match { case '[$qType] => - Expr.ofTupleFromSeq(Seq(nameExpr, '{ $s.selectDynamic($nameExpr).asInstanceOf[qType] })) + info.seal match { case '[t] => + Expr.ofTupleFromSeq(Seq(nameExpr, '{ $s.selectDynamic($nameExpr).asInstanceOf[t] })) } } @@ -91,8 +91,8 @@ object Macro { val refinementType = r.foldLeft(TypeRepr.of[T])((acc, e) => Refinement(acc, e._1, e._2)).seal - refinementType match { case '[$T] => - '{ $newRecord($s.toArray.map(e => e.asInstanceOf[(String, Any)])).asInstanceOf[T] } + refinementType match { case '[t] => + '{ $newRecord($s.toArray.map(e => e.asInstanceOf[(String, Any)])).asInstanceOf[t] } } } } diff --git a/tests/run-macros/string-context-implicits/Macro_1.scala b/tests/run-macros/string-context-implicits/Macro_1.scala index f17d99bd0a57..24ae3d535568 100644 --- a/tests/run-macros/string-context-implicits/Macro_1.scala +++ b/tests/run-macros/string-context-implicits/Macro_1.scala @@ -7,11 +7,11 @@ private def showMeExpr(sc: Expr[StringContext], argsExpr: Expr[Seq[Any]])(using argsExpr match { case Varargs(argExprs) => val argShowedExprs = argExprs.map { - case '{ $arg: $Tp } => - val showTp = Type[Show[Tp]] + case '{ $arg: tp } => + val showTp = Type[Show[tp]] Expr.summon(using showTp) match { case Some(showExpr) => '{ $showExpr.show($arg) } - case None => report.error(s"could not find implicit for ${Type.show[Show[Tp]]}", arg); '{???} + case None => report.error(s"could not find implicit for ${Type.show[Show[tp]]}", arg); '{???} } } val newArgsExpr = Varargs(argShowedExprs) diff --git a/tests/run-staging/quote-type-matcher.scala b/tests/run-staging/quote-type-matcher.scala index e6cef1a23767..895cc119a2dd 100644 --- a/tests/run-staging/quote-type-matcher.scala +++ b/tests/run-staging/quote-type-matcher.scala @@ -8,21 +8,21 @@ object Test { val '[List[Int]] = Type[List[Int]] Type[List[Int]] match - case '[List[$Int]] => - println(Type.show[Int]) + case '[List[int]] => + println(Type.show[int]) println() Type[Int => Double] match - case '[Function1[$T1, $R]] => - println(Type.show[T1]) - println(Type.show[R]) + case '[Function1[t1, r]] => + println(Type.show[t1]) + println(Type.show[r]) println() Type[(Int => Short) => Double] match - case '[Function1[Function1[$T1, $R0], $R]] => - println(Type.show[T1]) - println(Type.show[R0]) - println(Type.show[R]) + case '[Function1[Function1[t1, r0], r]] => + println(Type.show[t1]) + println(Type.show[r0]) + println(Type.show[r]) } }