@@ -113,6 +113,8 @@ class ReifyQuotes extends MacroTransformWithImplicits {
113
113
*/
114
114
val importedTags = new mutable.LinkedHashMap [TypeRef , Tree ]()
115
115
116
+ val explicitTags = new mutable.LinkedHashSet [TypeRef ]()
117
+
116
118
/** A stack of entered symbols, to be unwound after scope exit */
117
119
var enteredSyms : List [Symbol ] = Nil
118
120
@@ -129,23 +131,69 @@ class ReifyQuotes extends MacroTransformWithImplicits {
129
131
* as splices to `embedded`.
130
132
*/
131
133
private def addTags (expr : Tree )(implicit ctx : Context ): Tree =
132
- if (importedTags.isEmpty) expr
134
+ if (importedTags.isEmpty && explicitTags.isEmpty ) expr
133
135
else {
134
136
val itags = importedTags.toList
137
+
138
+ println(" addTags: expr: " + expr)
139
+ println(" addTags: tags: " )
140
+ itags.foreach(println)
141
+
135
142
val typeDefs = for ((tref, tag) <- itags) yield {
136
143
val rhs = transform(tag.select(tpnme.UNARY_~ ))
137
144
val alias = ctx.typeAssigner.assignType(untpd.TypeBoundsTree (rhs, rhs), rhs, rhs)
138
145
val original = tref.symbol.asType
139
146
val local = original.copy(
140
147
owner = ctx.owner,
148
+ name = (original.name + " $$" ).toTypeName,
141
149
flags = Synthetic ,
142
- info = TypeAlias (tag.tpe.select(tpnme.UNARY_~ )))
143
- ctx.typeAssigner.assignType(untpd.TypeDef (original.name, alias), local)
150
+ info = TypeAlias (tag.tpe.select(tpnme.UNARY_~ ))).asType
151
+
152
+ ctx.typeAssigner.assignType(untpd.TypeDef (local.name, alias), local)
144
153
}
145
154
importedTags.clear()
146
- Block (typeDefs,
147
- new TreeTypeMap (substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol))
155
+
156
+
157
+ val explicitTypeDefs = for (tref <- explicitTags) yield {
158
+ val tag = ref(tref.prefix.termSymbol)
159
+ val rhs = transform(tag.select(tpnme.UNARY_~ ))
160
+
161
+ val alias = ctx.typeAssigner.assignType(untpd.TypeBoundsTree (rhs, rhs), rhs, rhs)
162
+
163
+ val local = ctx.newSymbol(
164
+ owner = ctx.owner,
165
+ name = UniqueName .fresh(" ttt" .toTermName).toTypeName,
166
+ flags = Synthetic ,
167
+ info = TypeAlias (tag.tpe.select(tpnme.UNARY_~ )),
168
+ coord = tref.prefix.termSymbol.coord).asType
169
+
170
+ (tref, ctx.typeAssigner.assignType(untpd.TypeDef (local.name, alias), local))
171
+ }
172
+ val map : Map [Type , Type ] = explicitTypeDefs.map(x => (x._1, x._2.symbol.typeRef)).toMap
173
+
174
+ println()
175
+ println(map)
176
+ println()
177
+ println()
178
+
179
+ val tMap = new TypeMap () {
180
+ override def apply (tp : Type ): Type = {
181
+ if (map.contains(tp))
182
+ map.apply(tp)
183
+ else
184
+ mapOver(tp)
185
+ }
186
+ }
187
+
188
+ val ret = Block (typeDefs ++ explicitTypeDefs.map(_._2),
189
+ new TreeTypeMap (typeMap = tMap,
190
+ substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol))
148
191
.apply(expr))
192
+
193
+ println(" addTags: ret: " + ret)
194
+ println(ret.show)
195
+ println()
196
+ ret
149
197
}
150
198
151
199
/** Enter staging level of symbol defined by `tree`, if applicable. */
@@ -181,26 +229,30 @@ class ReifyQuotes extends MacroTransformWithImplicits {
181
229
* @return Some(msg) if unsuccessful where `msg` is a potentially empty error message
182
230
* to be added to the "inconsistent phase" message.
183
231
*/
184
- def tryHeal (tp : Type , pos : Position )(implicit ctx : Context ): Option [String ] = tp match {
185
- case tp : TypeRef =>
186
- if (level == 0 ) {
187
- None
188
- } else {
189
- val reqType = defn.QuotedTypeType .appliedTo(tp)
190
- val tag = ctx.typer.inferImplicitArg(reqType, pos)
191
- tag.tpe match {
192
- case fail : SearchFailureType =>
193
- Some (i """
194
- |
232
+ def tryHeal (tp : Type , pos : Position )(implicit ctx : Context ): Option [String ] = {
233
+ // println("tryHeal: " + tp)
234
+ tp match {
235
+ case tp : TypeRef =>
236
+ if (level == 0 ) {
237
+ None
238
+ } else {
239
+ val reqType = defn.QuotedTypeType .appliedTo(tp)
240
+ val tag = ctx.typer.inferImplicitArg(reqType, pos)
241
+ tag.tpe match {
242
+ case fail : SearchFailureType =>
243
+ Some (
244
+ i """
245
+ |
195
246
| The access would be accepted with the right type tag, but
196
- | ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
197
- case _ =>
198
- importedTags(tp) = nested(isQuote = false ).transform(tag)
199
- None
247
+ | ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
248
+ case _ =>
249
+ importedTags(tp) = nested(isQuote = false ).transform(tag)
250
+ None
251
+ }
200
252
}
201
- }
202
- case _ =>
203
- Some ( " " )
253
+ case _ =>
254
+ Some ( " " )
255
+ }
204
256
}
205
257
206
258
/** Check reference to `sym` for phase consistency, where `tp` is the underlying type
@@ -225,8 +277,11 @@ class ReifyQuotes extends MacroTransformWithImplicits {
225
277
def checkType (pos : Position )(implicit ctx : Context ): TypeAccumulator [Unit ] = new TypeAccumulator [Unit ] {
226
278
def apply (acc : Unit , tp : Type ): Unit = reporting.trace(i " check type level $tp at $level" ) {
227
279
tp match {
228
- case tp : NamedType if tp.symbol.isSplice =>
229
- if (inQuote) outer.checkType(pos).foldOver(acc, tp)
280
+ case tp : TypeRef if tp.symbol.isSplice =>
281
+ if (inQuote) {
282
+ explicitTags += tp
283
+ outer.checkType(pos).foldOver(acc, tp)
284
+ }
230
285
else {
231
286
if (tp.isTerm) spliceOutsideQuotes(pos)
232
287
tp
@@ -291,6 +346,13 @@ class ReifyQuotes extends MacroTransformWithImplicits {
291
346
}
292
347
else {
293
348
val (body1, splices) = nested(isQuote = true ).split(body)
349
+
350
+ // println()
351
+ // println("for quote: " + quote)
352
+ // println("body: " + body1)
353
+ // println("bodys: " + body1.show)
354
+
355
+ // splices.foreach(println)
294
356
pickledQuote(body1, splices, isType).withPos(quote.pos)
295
357
}
296
358
}
@@ -333,6 +395,12 @@ class ReifyQuotes extends MacroTransformWithImplicits {
333
395
}
334
396
else {
335
397
val (body1, quotes) = nested(isQuote = false ).split(splice.qualifier)
398
+ // println()
399
+ // println("for splice: " + splice)
400
+ // println("body: " + body1)
401
+ // println("bodys: " + body1.show)
402
+ //
403
+ // quotes.foreach(println)
336
404
makeHole(body1, quotes, splice.tpe).withPos(splice.pos)
337
405
}
338
406
}
@@ -432,7 +500,19 @@ class ReifyQuotes extends MacroTransformWithImplicits {
432
500
tree match {
433
501
case Quoted (quotedTree) =>
434
502
quotation(quotedTree, tree)
503
+ case tree : TypeTree if tree.tpe.typeSymbol.isSplice =>
504
+ val splicedType = tree.tpe.asInstanceOf [TypeRef ].prefix.termSymbol
505
+ val ret = splice(ref(splicedType).select(tpnme.UNARY_~ ))
506
+ // println()
507
+ // println("TypeTree: " + tree)
508
+ // println("TypeTrees: " + tree.show)
509
+ // println("TypeTree ret: " + ret)
510
+ // println("TypeTree rets: " + ret.show)
511
+ ret
512
+ case tree : TypeApply =>
513
+ super .transform(tree)
435
514
case tree : Select if tree.symbol.isSplice =>
515
+ // println("Select: " + tree)
436
516
splice(tree)
437
517
case tree : RefTree if needsLifting(tree) =>
438
518
val lift = lifters(tree.symbol)
@@ -441,7 +521,6 @@ class ReifyQuotes extends MacroTransformWithImplicits {
441
521
val last = enteredSyms
442
522
stats.foreach(markDef)
443
523
mapOverTree(last)
444
-
445
524
case Inlined (call, bindings, InlineSplice (expansion @ Select (body, name))) =>
446
525
// To maintain phase consistency, we move the binding of the this parameter into the spliced code
447
526
val (splicedBindings, stagedBindings) = bindings.partition {
0 commit comments