@@ -188,15 +188,19 @@ class Splicing extends MacroTransform:
188
188
* ```
189
189
*/
190
190
private class SpliceTransformer (spliceOwner : Symbol , isCaptured : Symbol => Boolean ) extends Transformer :
191
- private var refBindingMap = mutable.Map .empty[Symbol , (Tree , Symbol )]
191
+ private val typeBindingMap = mutable.Map .empty[Symbol , (Tree , Symbol )]
192
+ private val termBindingMap = mutable.Map .empty[Symbol , (Tree , Symbol )]
192
193
/** Reference to the `Quotes` instance of the current level 1 splice */
193
194
private var quotes : Tree | Null = null // TODO: add to the context
194
195
private var healedTypes : QuoteTypeTags | Null = null // TODO: add to the context
195
196
196
197
def transformSplice (tree : tpd.Tree , tpe : Type , holeIdx : Int )(using Context ): tpd.Tree =
197
198
assert(level == 0 )
198
199
val newTree = transform(tree)
199
- val (refs, bindings) = refBindingMap.values.toList.unzip
200
+ val (typeRefs, typeBindings) = typeBindingMap.values.toList.unzip
201
+ val (termRefs, termBindings) = termBindingMap.values.toList.unzip
202
+ val refs = typeRefs ::: termRefs
203
+ val bindings = typeBindings ::: termBindings
200
204
val bindingsTypes = bindings.map(_.termRef.widenTermRefExpr)
201
205
val methType = MethodType (bindingsTypes, newTree.tpe)
202
206
val meth = newSymbol(spliceOwner, nme.ANON_FUN , Synthetic | Method , methType)
@@ -348,7 +352,7 @@ class Splicing extends MacroTransform:
348
352
Param ,
349
353
defn.QuotedExprClass .typeRef.appliedTo(tpe),
350
354
)
351
- val bindingSym = refBindingMap .getOrElseUpdate(tree.symbol, (tree, newBinding))._2
355
+ val bindingSym = termBindingMap .getOrElseUpdate(tree.symbol, (tree, newBinding))._2
352
356
ref(bindingSym)
353
357
354
358
private def newQuotedTypeClassBinding (tpe : Type )(using Context ) =
@@ -361,7 +365,7 @@ class Splicing extends MacroTransform:
361
365
362
366
private def capturedType (tree : Tree )(using Context ): Symbol =
363
367
val tpe = tree.tpe.widenTermRefExpr
364
- val bindingSym = refBindingMap
368
+ val bindingSym = typeBindingMap
365
369
.getOrElseUpdate(tree.symbol, (TypeTree (tree.tpe), newQuotedTypeClassBinding(tpe)))._2
366
370
bindingSym
367
371
@@ -371,7 +375,7 @@ class Splicing extends MacroTransform:
371
375
val capturePartTypes = new TypeMap {
372
376
def apply (tp : Type ) = tp match {
373
377
case typeRef : TypeRef if containsCapturedType(typeRef) =>
374
- val termRef = refBindingMap
378
+ val termRef = typeBindingMap
375
379
.getOrElseUpdate(typeRef.symbol, (TypeTree (typeRef), newQuotedTypeClassBinding(typeRef)))._2.termRef
376
380
val tagRef = healedTypes.nn.getTagRef(termRef)
377
381
tagRef
0 commit comments