Skip to content

Fix #4023: Ignore healed implicit tag at level 0 #4038

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions compiler/src/dotty/tools/dotc/interpreter/Interpreter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,13 @@ class Interpreter(implicit ctx: Context) {
* If some error is encountered while interpreting a ctx.error is emitted and a StopInterpretation is thrown.
*/
private def interpretTreeImpl(tree: Tree, env: Env): Object = {
ctx.debuglog(
s"""Interpreting:
|${tree.show}
|$env
""".stripMargin)
// println(s"Interpreting:\n${tree.show}\n$env\n")

implicit val pos: Position = tree.pos

tree match {
case Quoted(quotedTree) =>
if (tree.isTerm) new scala.quoted.Exprs.TreeExpr(quotedTree)
if (quotedTree.isTerm) new scala.quoted.Exprs.TreeExpr(quotedTree)
else new scala.quoted.Types.TreeType(quotedTree)

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

case TypeApply(fn, _) =>
interpretTreeImpl(fn, env)

case Typed(expr, _) =>
interpretTreeImpl(expr, env)

Expand Down
28 changes: 17 additions & 11 deletions compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
*/
private class Reifier(inQuote: Boolean, val outer: Reifier, val level: Int, levels: LevelInfo) extends ImplicitsTransformer {
import levels._
assert(level >= 0)

/** A nested reifier for a quote (if `isQuote = true`) or a splice (if not) */
def nested(isQuote: Boolean): Reifier =
Expand Down Expand Up @@ -160,17 +161,22 @@ class ReifyQuotes extends MacroTransformWithImplicits {
*/
def tryHeal(tp: Type, pos: Position)(implicit ctx: Context): Option[String] = tp match {
case tp: TypeRef =>
val reqType = defn.QuotedTypeType.appliedTo(tp)
val tag = ctx.typer.inferImplicitArg(reqType, pos)
tag.tpe match {
case fail: SearchFailureType =>
Some(i"""
|
| The access would be accepted with the right type tag, but
| ${ctx.typer.missingArgMsg(tag, reqType, "")}""")
case _ =>
importedTags(tp) = nested(isQuote = false).transform(tag)
None
if (level == 0) {
assert(ctx.owner.is(Macro))
None
} else {
val reqType = defn.QuotedTypeType.appliedTo(tp)
val tag = ctx.typer.inferImplicitArg(reqType, pos)
tag.tpe match {
case fail: SearchFailureType =>
Some(i"""
|
| The access would be accepted with the right type tag, but
| ${ctx.typer.missingArgMsg(tag, reqType, "")}""")
case _ =>
importedTags(tp) = nested(isQuote = false).transform(tag)
None
}
}
case _ =>
Some("")
Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/transform/Splicer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ object Splicer {
*/
def splice(tree: Tree)(implicit ctx: Context): Tree = tree match {
case Quoted(quotedTree) => quotedTree
case tree: RefTree => reflectiveSplice(tree)
case tree: Apply => reflectiveSplice(tree)
case tree: Inlined => reflectiveSplice(tree)
case tree: Block => reflectiveSplice(tree)
case _ => reflectiveSplice(tree)
}

/** Splice the Tree for a Quoted expression which is constructed via a reflective call to the given method */
Expand Down
5 changes: 5 additions & 0 deletions tests/pos/i4023/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scala.quoted._
object Macro {
inline def ff[T: Type](x: T): T = ~impl('(x))
def impl[T](x: Expr[T]): Expr[T] = x
}
3 changes: 3 additions & 0 deletions tests/pos/i4023/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
Macro.ff(3)
}
5 changes: 5 additions & 0 deletions tests/pos/i4023b/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scala.quoted._
object Macro {
inline def ff[T](implicit t: Type[T]): Int = ~impl[T]
def impl[T]: Expr[Int] = 4
}
3 changes: 3 additions & 0 deletions tests/pos/i4023b/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
Macro.ff[Int]
}
5 changes: 5 additions & 0 deletions tests/pos/i4023c/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scala.quoted._
object Macro {
inline def ff[T](x: T): T = ~impl('(x), '[T])
def impl[T](x: Expr[T], t: Type[T]): Expr[T] = '{ (~x): ~t }
}
7 changes: 7 additions & 0 deletions tests/pos/i4023c/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
object Test {
Macro.ff(3)

def f[T](x: T) = {
Macro.ff(x)
}
}
5 changes: 5 additions & 0 deletions tests/pos/macro-with-type/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import scala.quoted._
object Macro {
inline def ff: Unit = ~impl('[Int])
def impl(t: Type[Int]): Expr[Unit] = ()
}
3 changes: 3 additions & 0 deletions tests/pos/macro-with-type/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Test {
Macro.ff
}