Skip to content

Commit bedbd5a

Browse files
authored
Merge pull request #4038 from dotty-staging/fix-#4023
Fix #4023: Ignore healed implicit tag at level 0
2 parents 8bd1625 + 7a5a91e commit bedbd5a

File tree

11 files changed

+59
-21
lines changed

11 files changed

+59
-21
lines changed

compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,13 @@ class Interpreter(implicit ctx: Context) {
6363
* If some error is encountered while interpreting a ctx.error is emitted and a StopInterpretation is thrown.
6464
*/
6565
private def interpretTreeImpl(tree: Tree, env: Env): Object = {
66-
ctx.debuglog(
67-
s"""Interpreting:
68-
|${tree.show}
69-
|$env
70-
""".stripMargin)
66+
// println(s"Interpreting:\n${tree.show}\n$env\n")
7167

7268
implicit val pos: Position = tree.pos
7369

7470
tree match {
7571
case Quoted(quotedTree) =>
76-
if (tree.isTerm) new scala.quoted.Exprs.TreeExpr(quotedTree)
72+
if (quotedTree.isTerm) new scala.quoted.Exprs.TreeExpr(quotedTree)
7773
else new scala.quoted.Types.TreeType(quotedTree)
7874

7975
case Literal(Constant(c)) => c.asInstanceOf[Object]
@@ -114,6 +110,9 @@ class Interpreter(implicit ctx: Context) {
114110
val env2 = bindings.foldLeft(env)((acc, x) => interpretStat(x, acc))
115111
interpretTreeImpl(expansion, env2)
116112

113+
case TypeApply(fn, _) =>
114+
interpretTreeImpl(fn, env)
115+
117116
case Typed(expr, _) =>
118117
interpretTreeImpl(expr, env)
119118

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
7777
*/
7878
private class Reifier(inQuote: Boolean, val outer: Reifier, val level: Int, levels: LevelInfo) extends ImplicitsTransformer {
7979
import levels._
80+
assert(level >= 0)
8081

8182
/** A nested reifier for a quote (if `isQuote = true`) or a splice (if not) */
8283
def nested(isQuote: Boolean): Reifier =
@@ -160,17 +161,22 @@ class ReifyQuotes extends MacroTransformWithImplicits {
160161
*/
161162
def tryHeal(tp: Type, pos: Position)(implicit ctx: Context): Option[String] = tp match {
162163
case tp: TypeRef =>
163-
val reqType = defn.QuotedTypeType.appliedTo(tp)
164-
val tag = ctx.typer.inferImplicitArg(reqType, pos)
165-
tag.tpe match {
166-
case fail: SearchFailureType =>
167-
Some(i"""
168-
|
169-
| The access would be accepted with the right type tag, but
170-
| ${ctx.typer.missingArgMsg(tag, reqType, "")}""")
171-
case _ =>
172-
importedTags(tp) = nested(isQuote = false).transform(tag)
173-
None
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 _ =>
177+
importedTags(tp) = nested(isQuote = false).transform(tag)
178+
None
179+
}
174180
}
175181
case _ =>
176182
Some("")

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,7 @@ object Splicer {
1616
*/
1717
def splice(tree: Tree)(implicit ctx: Context): Tree = tree match {
1818
case Quoted(quotedTree) => quotedTree
19-
case tree: RefTree => reflectiveSplice(tree)
20-
case tree: Apply => reflectiveSplice(tree)
21-
case tree: Inlined => reflectiveSplice(tree)
22-
case tree: Block => reflectiveSplice(tree)
19+
case _ => reflectiveSplice(tree)
2320
}
2421

2522
/** Splice the Tree for a Quoted expression which is constructed via a reflective call to the given method */

tests/pos/i4023/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: Type](x: T): T = ~impl('(x))
4+
def impl[T](x: Expr[T]): Expr[T] = x
5+
}

tests/pos/i4023/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test {
2+
Macro.ff(3)
3+
}

tests/pos/i4023b/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](implicit t: Type[T]): Int = ~impl[T]
4+
def impl[T]: Expr[Int] = 4
5+
}

tests/pos/i4023b/Test_2.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test {
2+
Macro.ff[Int]
3+
}

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+
}
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: Unit = ~impl('[Int])
4+
def impl(t: Type[Int]): Expr[Unit] = ()
5+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
object Test {
2+
Macro.ff
3+
}

0 commit comments

Comments
 (0)