Skip to content

Commit 7a5a91e

Browse files
committed
Fix staged quoted.Type in macro
1 parent 3779c8e commit 7a5a91e

File tree

3 files changed

+27
-11
lines changed

3 files changed

+27
-11
lines changed

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -161,18 +161,22 @@ class ReifyQuotes extends MacroTransformWithImplicits {
161161
*/
162162
def tryHeal(tp: Type, pos: Position)(implicit ctx: Context): Option[String] = tp match {
163163
case tp: TypeRef =>
164-
val reqType = defn.QuotedTypeType.appliedTo(tp)
165-
val tag = ctx.typer.inferImplicitArg(reqType, pos)
166-
tag.tpe match {
167-
case fail: SearchFailureType =>
168-
Some(i"""
169-
|
170-
| The access would be accepted with the right type tag, but
171-
| ${ctx.typer.missingArgMsg(tag, reqType, "")}""")
172-
case _ =>
173-
if (level > 0) // TODO do we need to find the tag for level 0?
164+
if (level == 0) {
165+
assert(ctx.owner.is(Macro))
166+
None
167+
} else {
168+
val reqType = defn.QuotedTypeType.appliedTo(tp)
169+
val tag = ctx.typer.inferImplicitArg(reqType, pos)
170+
tag.tpe match {
171+
case fail: SearchFailureType =>
172+
Some(i"""
173+
|
174+
| The access would be accepted with the right type tag, but
175+
| ${ctx.typer.missingArgMsg(tag, reqType, "")}""")
176+
case _ =>
174177
importedTags(tp) = nested(isQuote = false).transform(tag)
175-
None
178+
None
179+
}
176180
}
177181
case _ =>
178182
Some("")

tests/pos/i4023c/Macro_1.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import scala.quoted._
2+
object Macro {
3+
inline def ff[T](x: T): T = ~impl('(x), '[T])
4+
def impl[T](x: Expr[T], t: Type[T]): Expr[T] = '{ (~x): ~t }
5+
}

tests/pos/i4023c/Test_2.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
object Test {
2+
Macro.ff(3)
3+
4+
def f[T](x: T) = {
5+
Macro.ff(x)
6+
}
7+
}

0 commit comments

Comments
 (0)