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