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