@@ -24,6 +24,7 @@ import dotty.tools.dotc.util.Spans._
24
24
import dotty .tools .dotc .util .Stats .record
25
25
import dotty .tools .dotc .reporting .IllegalVariableInPatternAlternative
26
26
import scala .collection .mutable
27
+ import scala .collection .collection .SeqMap
27
28
28
29
29
30
/** Type quotes `'{ ... }` and splices `${ ... }` */
@@ -190,7 +191,7 @@ trait QuotesAndSplices {
190
191
* will return
191
192
* ```
192
193
* (
193
- * Map(<t$giveni>: Symbol -> <t @ _ >: Bind ),
194
+ * Map(<t$giveni>: Symbol -> <t>: Symbol ),
194
195
* <'{
195
196
* @scala.internal.Quoted.patternType type t
196
197
* scala.internal.Quoted.patternHole[List[t]]
@@ -199,10 +200,10 @@ trait QuotesAndSplices {
199
200
* )
200
201
* ```
201
202
*/
202
- private def splitQuotePattern (quoted : Tree )(using Context ): (collection. Map [Symbol , Bind ], Tree , List [Tree ]) = {
203
+ private def splitQuotePattern (quoted : Tree )(using Context ): (SeqMap [Symbol , Symbol ], Tree , List [Tree ]) = {
203
204
val ctx0 = ctx
204
205
205
- val bindSymMapping : collection. Map [Symbol , Bind ] = unapplyBindingsMapping(quoted)
206
+ val bindSymMapping : SeqMap [Symbol , Symbol ] = unapplyBindingsMapping(quoted)
206
207
207
208
object splitter extends tpd.TreeMap {
208
209
private var variance : Int = 1
@@ -282,7 +283,7 @@ trait QuotesAndSplices {
282
283
report.error(IllegalVariableInPatternAlternative (tdef.symbol.name), tdef.srcPos)
283
284
if variance == - 1 then
284
285
tdef.symbol.addAnnotation(Annotation (New (ref(defn.QuotedRuntimePatterns_fromAboveAnnot .typeRef)).withSpan(tdef.span)))
285
- val bindingType = bindSymMapping(tdef.symbol).symbol. typeRef
286
+ val bindingType = bindSymMapping(tdef.symbol).typeRef
286
287
val bindingTypeTpe = AppliedType (defn.QuotedTypeClass .typeRef, bindingType :: Nil )
287
288
val sym = newPatternBoundSymbol(nameOfSyntheticGiven, bindingTypeTpe, tdef.span, flags = ImplicitVal )(using ctx0)
288
289
buff += Bind (sym, untpd.Ident (nme.WILDCARD ).withType(bindingTypeTpe)).withSpan(tdef.span)
@@ -326,10 +327,10 @@ trait QuotesAndSplices {
326
327
* binding that will be as type variable in the encoded `unapply` of the quote pattern.
327
328
*
328
329
* @return Mapping from type variable symbols defined in the quote pattern into
329
- * type variable `Bind` definitions for the `unapply` of the quote pattern.
330
+ * type variable definitions for the `unapply` of the quote pattern.
330
331
* This mapping retains the original type variable definition order.
331
332
*/
332
- private def unapplyBindingsMapping (quoted : Tree )(using Context ): collection. Map [Symbol , Bind ] = {
333
+ private def unapplyBindingsMapping (quoted : Tree )(using Context ): SeqMap [Symbol , Symbol ] = {
333
334
// Collect all existing type variable bindings and create new symbols for them.
334
335
// The old info is used, it may contain references to the old symbols.
335
336
val (oldBindings, newBindings) = {
@@ -367,8 +368,7 @@ trait QuotesAndSplices {
367
368
ctx.gadtState.addToConstraint(newBindings) // This must be performed after the info has been updated
368
369
369
370
// Map into Bind nodes retaining the original order
370
- val newBindingBinds = newBindings.map(newSym => Bind (newSym, untpd.Ident (nme.WILDCARD ).withType(newSym.info)).withSpan(quoted.span))
371
- mutable.LinkedHashMap .from(oldBindings.lazyZip(newBindingBinds))
371
+ mutable.LinkedHashMap .from(oldBindings.lazyZip(newBindings))
372
372
}
373
373
374
374
/** Type a quote pattern `case '{ <quoted> } =>` qiven the a current prototype. Typing the pattern
@@ -434,20 +434,23 @@ trait QuotesAndSplices {
434
434
if quoted.isType then typedType(quoted0, WildcardType )(using quoteCtx)
435
435
else typedExpr(quoted0, WildcardType )(using quoteCtx)
436
436
437
- val (typeBindings , shape, splices) = splitQuotePattern(quoted1)
437
+ val (bindSymMapping , shape, splices) = splitQuotePattern(quoted1)
438
438
439
439
class ReplaceBindings extends TypeMap () {
440
440
override def apply (tp : Type ): Type = tp match {
441
441
case tp : TypeRef =>
442
442
val tp1 = if (tp.symbol.isTypeSplice) tp.dealias else tp
443
- mapOver(typeBindings .get(tp1.typeSymbol).fold(tp)(_.symbol .typeRef))
443
+ mapOver(bindSymMapping .get(tp1.typeSymbol).fold(tp)(_.typeRef))
444
444
case tp => mapOver(tp)
445
445
}
446
446
}
447
447
val replaceBindings = new ReplaceBindings
448
448
val patType = defn.tupleType(splices.tpes.map(tpe => replaceBindings(tpe.widen)))
449
449
450
- val typeBindingsTuple = tpd.hkNestedPairsTypeTree(typeBindings.values.toList)
450
+ val typeBinds = bindSymMapping.values.toList.map(sym =>
451
+ Bind (sym, untpd.Ident (nme.WILDCARD ).withType(sym.info)).withSpan(quoted.span)
452
+ )
453
+ val typeBindingsTuple = tpd.hkNestedPairsTypeTree(typeBinds)
451
454
452
455
val replaceBindingsInTree = new TreeMap {
453
456
private var bindMap = Map .empty[Symbol , Symbol ]
0 commit comments