@@ -9,7 +9,7 @@ import dotty.tools.dotc.core.Constants._
99import dotty .tools .dotc .core .Contexts ._
1010import dotty .tools .dotc .core .Decorators ._
1111import dotty .tools .dotc .core .Flags ._
12- import dotty .tools .dotc .core .NameKinds .UniqueName
12+ import dotty .tools .dotc .core .NameKinds .{ UniqueName , PatMatVarName }
1313import dotty .tools .dotc .core .Names ._
1414import dotty .tools .dotc .core .StagingContext ._
1515import dotty .tools .dotc .core .StdNames ._
@@ -156,19 +156,21 @@ trait QuotesAndSplices {
156156 if ctx.mode.is(Mode .QuotedPattern ) && level == 1 then
157157 def spliceOwner (ctx : Context ): Symbol =
158158 if (ctx.mode.is(Mode .QuotedPattern )) spliceOwner(ctx.outer) else ctx.owner
159- val name = tree.expr match {
160- case Ident (name) => (" $" + name).toTypeName
159+ val (name, expr) = tree.expr match {
160+ case Ident (name) =>
161+ val nameOfSyntheticGiven = PatMatVarName .fresh()
162+ (name.toTypeName, untpd.cpy.Ident (tree.expr)(nameOfSyntheticGiven))
161163 case expr =>
162164 report.error(" expected a name binding" , expr.srcPos)
163- " $error" .toTypeName
165+ ( " $error" .toTypeName, expr)
164166 }
165167
166168 val typeSymInfo = pt match
167169 case pt : TypeBounds => pt
168170 case _ => TypeBounds .empty
169171 val typeSym = newSymbol(spliceOwner(ctx), name, EmptyFlags , typeSymInfo, NoSymbol , tree.expr.span)
170172 typeSym.addAnnotation(Annotation (New (ref(defn.InternalQuotedPatterns_patternTypeAnnot .typeRef)).withSpan(tree.expr.span)))
171- val pat = typedPattern(tree. expr, defn.QuotedTypeClass .typeRef.appliedTo(typeSym.typeRef))(
173+ val pat = typedPattern(expr, defn.QuotedTypeClass .typeRef.appliedTo(typeSym.typeRef))(
172174 using spliceContext.retractMode(Mode .QuotedPattern ).withOwner(spliceOwner(ctx)))
173175 pat.select(tpnme.spliceType)
174176 else
@@ -214,7 +216,7 @@ trait QuotesAndSplices {
214216 def getBinding (sym : Symbol ): Bind =
215217 typeBindings.getOrElseUpdate(sym, {
216218 val bindingBounds = sym.info
217- val bsym = newPatternBoundSymbol(sym.name.toTypeName, bindingBounds, quoted.span)
219+ val bsym = newPatternBoundSymbol(sym.name.toString.stripPrefix( " $ " ). toTypeName, bindingBounds, quoted.span)
218220 Bind (bsym, untpd.Ident (nme.WILDCARD ).withType(bindingBounds)).withSpan(quoted.span)
219221 })
220222
@@ -263,13 +265,14 @@ trait QuotesAndSplices {
263265 val sym = tree.tpe.dealias.typeSymbol
264266 if sym.exists then
265267 val tdef = TypeDef (sym.asType).withSpan(sym.span)
266- freshTypeBindingsBuff += transformTypeBindingTypeDef(tdef, freshTypePatBuf)
268+ val nameOfSyntheticGiven = pat.symbol.name.toTermName
269+ freshTypeBindingsBuff += transformTypeBindingTypeDef(nameOfSyntheticGiven, tdef, freshTypePatBuf)
267270 TypeTree (tree.tpe.dealias).withSpan(tree.span)
268271 else
269272 tree
270273 case tdef : TypeDef =>
271274 if tdef.symbol.hasAnnotation(defn.InternalQuotedPatterns_patternTypeAnnot ) then
272- transformTypeBindingTypeDef(tdef, typePatBuf)
275+ transformTypeBindingTypeDef(PatMatVarName .fresh(), tdef, typePatBuf)
273276 else if tdef.symbol.isClass then
274277 val kind = if tdef.symbol.is(Module ) then " objects" else " classes"
275278 report.error(" Implementation restriction: cannot match " + kind, tree.srcPos)
@@ -305,13 +308,12 @@ trait QuotesAndSplices {
305308 super .transform(tree)
306309 }
307310
308- private def transformTypeBindingTypeDef (tdef : TypeDef , buff : mutable.Builder [Tree , List [Tree ]])(using Context ): Tree = {
311+ private def transformTypeBindingTypeDef (nameOfSyntheticGiven : TermName , tdef : TypeDef , buff : mutable.Builder [Tree , List [Tree ]])(using Context ): Tree = {
309312 if (variance == - 1 )
310313 tdef.symbol.addAnnotation(Annotation (New (ref(defn.InternalQuotedPatterns_fromAboveAnnot .typeRef)).withSpan(tdef.span)))
311314 val bindingType = getBinding(tdef.symbol).symbol.typeRef
312315 val bindingTypeTpe = AppliedType (defn.QuotedTypeClass .typeRef, bindingType :: Nil )
313- val bindName = tdef.name.toString.stripPrefix(" $" ).toTermName
314- val sym = newPatternBoundSymbol(bindName, bindingTypeTpe, tdef.span, flags = ImplicitTerm )(using ctx0)
316+ val sym = newPatternBoundSymbol(nameOfSyntheticGiven, bindingTypeTpe, tdef.span, flags = ImplicitTerm )(using ctx0)
315317 buff += Bind (sym, untpd.Ident (nme.WILDCARD ).withType(bindingTypeTpe)).withSpan(tdef.span)
316318 super .transform(tdef)
317319 }
0 commit comments