@@ -113,6 +113,8 @@ class ReifyQuotes extends MacroTransformWithImplicits {
113113 */
114114 val importedTags = new mutable.LinkedHashMap [TypeRef , Tree ]()
115115
116+ val explicitTags = new mutable.LinkedHashSet [TypeRef ]()
117+
116118 /** A stack of entered symbols, to be unwound after scope exit */
117119 var enteredSyms : List [Symbol ] = Nil
118120
@@ -129,7 +131,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
129131 * as splices to `embedded`.
130132 */
131133 private def addTags (expr : Tree )(implicit ctx : Context ): Tree =
132- if (importedTags.isEmpty) expr
134+ if (importedTags.isEmpty && explicitTags.isEmpty ) expr
133135 else {
134136 val itags = importedTags.toList
135137 val typeDefs = for ((tref, tag) <- itags) yield {
@@ -138,13 +140,43 @@ class ReifyQuotes extends MacroTransformWithImplicits {
138140 val original = tref.symbol.asType
139141 val local = original.copy(
140142 owner = ctx.owner,
143+ name = (original.name + " $$" ).toTypeName,
141144 flags = Synthetic ,
142- info = TypeAlias (tag.tpe.select(tpnme.UNARY_~ )))
143- ctx.typeAssigner.assignType(untpd.TypeDef (original.name, alias), local)
145+ info = TypeAlias (tag.tpe.select(tpnme.UNARY_~ ))).asType
146+
147+ ctx.typeAssigner.assignType(untpd.TypeDef (local.name, alias), local)
144148 }
145149 importedTags.clear()
146- Block (typeDefs,
147- new TreeTypeMap (substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol))
150+
151+
152+ val explicitTypeDefs = for (tref <- explicitTags) yield {
153+ val tag = ref(tref.prefix.termSymbol)
154+ val rhs = transform(tag.select(tpnme.UNARY_~ ))
155+
156+ val alias = ctx.typeAssigner.assignType(untpd.TypeBoundsTree (rhs, rhs), rhs, rhs)
157+
158+ val local = ctx.newSymbol(
159+ owner = ctx.owner,
160+ name = UniqueName .fresh(" ttt" .toTermName).toTypeName,
161+ flags = Synthetic ,
162+ info = TypeAlias (tag.tpe.select(tpnme.UNARY_~ )),
163+ coord = tref.prefix.termSymbol.coord).asType
164+
165+ (tref, ctx.typeAssigner.assignType(untpd.TypeDef (local.name, alias), local))
166+ }
167+ val map : Map [Type , Type ] = explicitTypeDefs.map(x => (x._1, x._2.symbol.typeRef)).toMap
168+ val tMap = new TypeMap () {
169+ override def apply (tp : Type ): Type = {
170+ if (map.contains(tp))
171+ map.apply(tp)
172+ else
173+ mapOver(tp)
174+ }
175+ }
176+
177+ Block (typeDefs ++ explicitTypeDefs.map(_._2),
178+ new TreeTypeMap (typeMap = tMap,
179+ substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol))
148180 .apply(expr))
149181 }
150182
@@ -226,8 +258,11 @@ class ReifyQuotes extends MacroTransformWithImplicits {
226258 def checkType (pos : Position )(implicit ctx : Context ): TypeAccumulator [Unit ] = new TypeAccumulator [Unit ] {
227259 def apply (acc : Unit , tp : Type ): Unit = reporting.trace(i " check type level $tp at $level" ) {
228260 tp match {
229- case tp : NamedType if tp.symbol.isSplice =>
230- if (inQuote) outer.checkType(pos).foldOver(acc, tp)
261+ case tp : TypeRef if tp.symbol.isSplice =>
262+ if (inQuote) {
263+ explicitTags += tp
264+ outer.checkType(pos).foldOver(acc, tp)
265+ }
231266 else {
232267 if (tp.isTerm) spliceOutsideQuotes(pos)
233268 tp
0 commit comments