@@ -25,6 +25,7 @@ import dotty.tools.dotc.util.Spans._
25
25
import dotty .tools .dotc .util .Stats .record
26
26
import dotty .tools .dotc .reporting .IllegalVariableInPatternAlternative
27
27
import scala .collection .mutable
28
+ import scala .collection .collection .SeqMap
28
29
29
30
/** Type quotes `'{ ... }` and splices `${ ... }` */
30
31
trait QuotesAndSplices {
@@ -202,7 +203,7 @@ trait QuotesAndSplices {
202
203
* will return
203
204
* ```
204
205
* (
205
- * Map(<t$giveni>: Symbol -> <t @ _ >: Bind ),
206
+ * Map(<t$giveni>: Symbol -> <t>: Symbol ),
206
207
* <'{
207
208
* @scala.internal.Quoted.patternType type t
208
209
* scala.internal.Quoted.patternHole[List[t]]
@@ -211,10 +212,10 @@ trait QuotesAndSplices {
211
212
* )
212
213
* ```
213
214
*/
214
- private def splitQuotePattern (quoted : Tree )(using Context ): (collection. Map [Symbol , Bind ], Tree , List [Tree ]) = {
215
+ private def splitQuotePattern (quoted : Tree )(using Context ): (SeqMap [Symbol , Symbol ], Tree , List [Tree ]) = {
215
216
val ctx0 = ctx
216
217
217
- val bindSymMapping : collection. Map [Symbol , Bind ] = unapplyBindingsMapping(quoted)
218
+ val bindSymMapping : SeqMap [Symbol , Symbol ] = unapplyBindingsMapping(quoted)
218
219
219
220
object splitter extends tpd.TreeMap {
220
221
private var variance : Int = 1
@@ -294,7 +295,7 @@ trait QuotesAndSplices {
294
295
report.error(IllegalVariableInPatternAlternative (tdef.symbol.name), tdef.srcPos)
295
296
if variance == - 1 then
296
297
tdef.symbol.addAnnotation(Annotation (New (ref(defn.QuotedRuntimePatterns_fromAboveAnnot .typeRef)).withSpan(tdef.span)))
297
- val bindingType = bindSymMapping(tdef.symbol).symbol. typeRef
298
+ val bindingType = bindSymMapping(tdef.symbol).typeRef
298
299
val bindingTypeTpe = AppliedType (defn.QuotedTypeClass .typeRef, bindingType :: Nil )
299
300
val sym = newPatternBoundSymbol(nameOfSyntheticGiven, bindingTypeTpe, tdef.span, flags = ImplicitVal )(using ctx0)
300
301
buff += Bind (sym, untpd.Ident (nme.WILDCARD ).withType(bindingTypeTpe)).withSpan(tdef.span)
@@ -338,10 +339,10 @@ trait QuotesAndSplices {
338
339
* binding that will be as type variable in the encoded `unapply` of the quote pattern.
339
340
*
340
341
* @return Mapping from type variable symbols defined in the quote pattern into
341
- * type variable `Bind` definitions for the `unapply` of the quote pattern.
342
+ * type variable definitions for the `unapply` of the quote pattern.
342
343
* This mapping retains the original type variable definition order.
343
344
*/
344
- private def unapplyBindingsMapping (quoted : Tree )(using Context ): collection. Map [Symbol , Bind ] = {
345
+ private def unapplyBindingsMapping (quoted : Tree )(using Context ): SeqMap [Symbol , Symbol ] = {
345
346
// Collect all existing type variable bindings and create new symbols for them.
346
347
// The old info is used, it may contain references to the old symbols.
347
348
val (oldBindings, newBindings) = {
@@ -379,8 +380,7 @@ trait QuotesAndSplices {
379
380
ctx.gadtState.addToConstraint(newBindings) // This must be performed after the info has been updated
380
381
381
382
// Map into Bind nodes retaining the original order
382
- val newBindingBinds = newBindings.map(newSym => Bind (newSym, untpd.Ident (nme.WILDCARD ).withType(newSym.info)).withSpan(quoted.span))
383
- mutable.LinkedHashMap .from(oldBindings.lazyZip(newBindingBinds))
383
+ mutable.LinkedHashMap .from(oldBindings.lazyZip(newBindings))
384
384
}
385
385
386
386
/** Type a quote pattern `case '{ <quoted> } =>` qiven the a current prototype. Typing the pattern
@@ -470,20 +470,23 @@ trait QuotesAndSplices {
470
470
else tpd.Block (typeTypeVariables, pattern)
471
471
}
472
472
473
- val (typeBindings , shape, splices) = splitQuotePattern(quoted1)
473
+ val (bindSymMapping , shape, splices) = splitQuotePattern(quoted1)
474
474
475
475
class ReplaceBindings extends TypeMap () {
476
476
override def apply (tp : Type ): Type = tp match {
477
477
case tp : TypeRef =>
478
478
val tp1 = if (tp.symbol.isTypeSplice) tp.dealias else tp
479
- mapOver(typeBindings .get(tp1.typeSymbol).fold(tp)(_.symbol .typeRef))
479
+ mapOver(bindSymMapping .get(tp1.typeSymbol).fold(tp)(_.typeRef))
480
480
case tp => mapOver(tp)
481
481
}
482
482
}
483
483
val replaceBindings = new ReplaceBindings
484
484
val patType = defn.tupleType(splices.tpes.map(tpe => replaceBindings(tpe.widen)))
485
485
486
- val typeBindingsTuple = tpd.hkNestedPairsTypeTree(typeBindings.values.toList)
486
+ val typeBinds = bindSymMapping.values.toList.map(sym =>
487
+ Bind (sym, untpd.Ident (nme.WILDCARD ).withType(sym.info)).withSpan(quoted.span)
488
+ )
489
+ val typeBindingsTuple = tpd.hkNestedPairsTypeTree(typeBinds)
487
490
488
491
val replaceBindingsInTree = new TreeMap {
489
492
private var bindMap = Map .empty[Symbol , Symbol ]
0 commit comments