@@ -253,10 +253,10 @@ class ReifyQuotes extends MacroTransformWithImplicits {
253
253
254
254
/** Try to heal phase-inconsistent reference to type `T` using a local type definition.
255
255
* @return None if successful
256
- * @return Some(msg) if unsuccessful where `msg` is a potentially empty error message
257
- * to be added to the "inconsistent phase" message.
256
+ * @return Some(Left( msg) ) if unsuccessful where `msg` is a potentially empty error message
257
+ * @return Some(Right(ttag)) the type tag that heals the inconcistency
258
258
*/
259
- def tryHeal (tp : Type , pos : Position )(implicit ctx : Context ): Option [String ] = tp match {
259
+ def tryHeal (tp : Type , pos : Position )(implicit ctx : Context ): Option [Either [ String , Tree ] ] = tp match {
260
260
case tp : TypeRef =>
261
261
if (level == - 1 ) {
262
262
assert(ctx.inInlineMethod)
@@ -266,37 +266,43 @@ class ReifyQuotes extends MacroTransformWithImplicits {
266
266
val tag = ctx.typer.inferImplicitArg(reqType, pos)
267
267
tag.tpe match {
268
268
case fail : SearchFailureType =>
269
- Some (i """
269
+ Some (Left ( i """
270
270
|
271
271
| The access would be accepted with the right type tag, but
272
- | ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
272
+ | ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" ))
273
273
case _ =>
274
- importedTags(tp) = nested(isQuote = false ).transform(tag)
275
- None
274
+ Some ( Right ( nested(isQuote = false ).transform(tag)) )
275
+
276
276
}
277
277
}
278
278
case _ =>
279
- Some (" " )
279
+ Some (Left ( " " ) )
280
280
}
281
281
282
282
/** Check reference to `sym` for phase consistency, where `tp` is the underlying type
283
283
* by which we refer to `sym`.
284
284
*/
285
- def check (sym : Symbol , tp : Type , pos : Position )(implicit ctx : Context ): Unit = {
285
+ def check (sym : Symbol , tp : Type , pos : Position )(implicit ctx : Context ): Option [ Tree ] = {
286
286
val isThis = tp.isInstanceOf [ThisType ]
287
287
def symStr =
288
288
if (! isThis) sym.show
289
289
else if (sym.is(ModuleClass )) sym.sourceModule.show
290
290
else i " ${sym.name}.this "
291
- if (! isThis && sym.maybeOwner.isType && ! sym.is(Param ))
291
+ if (! isThis && sym.maybeOwner.isType && ! sym.is(Param )) {
292
292
check(sym.owner, sym.owner.thisType, pos)
293
- else if (level == 1 && sym.isType && sym.is(Param ) && sym.owner.isInlineMethod && ! outer.isRoot)
294
- importedTags(sym.typeRef) = capturers(sym)(ref(sym))
295
- else if (sym.exists && ! sym.isStaticOwner && ! levelOK(sym))
296
- for (errMsg <- tryHeal(tp, pos))
297
- ctx.error(em """ access to $symStr from wrong staging level:
293
+ } else if (level == 1 && sym.isType && sym.is(Param ) && sym.owner.isInlineMethod && ! outer.isRoot) {
294
+ Some (capturers(sym)(ref(sym)))
295
+ } else if (sym.exists && ! sym.isStaticOwner && ! levelOK(sym)) {
296
+ tryHeal(tp, pos) match {
297
+ case Some (Left (errMsg)) =>
298
+ ctx.error(em """ access to $symStr from wrong staging level:
298
299
| - the definition is at level ${levelOf.getOrElse(sym, 0 )},
299
300
| - but the access is at level $level. $errMsg""" , pos)
301
+ None
302
+ case Some (Right (ttag)) => Some (ttag)
303
+ case None => None
304
+ }
305
+ } else None
300
306
}
301
307
302
308
/** Check all named types and this-types in a given type for phase consistency. */
@@ -341,18 +347,26 @@ class ReifyQuotes extends MacroTransformWithImplicits {
341
347
private def checkLevel (tree : Tree )(implicit ctx : Context ): Tree = {
342
348
tree match {
343
349
case (_ : Ident ) | (_ : This ) =>
344
- check(tree.symbol, tree.tpe, tree.pos)
350
+ check(tree.symbol, tree.tpe, tree.pos) match {
351
+ case Some (ttag) =>
352
+ transform(ttag.select(tpnme.UNARY_~ ))
353
+ case _ => tree
354
+ }
345
355
case (_ : UnApply ) | (_ : TypeTree ) =>
346
356
checkType(tree.pos).apply((), tree.tpe)
357
+ tree
347
358
case Select (qual, OuterSelectName (_, levels)) =>
348
359
checkType(tree.pos).apply((), tree.tpe.widen)
360
+ tree
349
361
case _ : Bind =>
350
362
checkType(tree.pos).apply((), tree.symbol.info)
363
+ tree
351
364
case _ : Template =>
352
365
checkType(tree.pos).apply((), tree.symbol.owner.asClass.givenSelfType)
366
+ tree
353
367
case _ =>
368
+ tree
354
369
}
355
- tree
356
370
}
357
371
358
372
/** Split `body` into a core and a list of embedded splices.
0 commit comments