Permalink
Browse files

SI-7047 fixes silent for c.inferImplicitXXX

This is a port of b4da864 from 2.10.x.
  • Loading branch information...
1 parent c539ae2 commit b1538804043bdd7036a6378a9146b685db03a4ba @xeno-by xeno-by committed Feb 23, 2013
@@ -54,10 +54,13 @@ trait Typers {
wrapper(universe.analyzer.inferImplicit(tree, pt, reportAmbiguous = true, isView = isView, context = context, saveAmbiguousDivergent = !silent, pos = pos)) match {
case failure if failure.tree.isEmpty =>
macroLogVerbose("implicit search has failed. to find out the reason, turn on -Xlog-implicits")
- context.firstError match {
- case Some(err) => throw new TypecheckException(err.errPos, err.errMsg)
- case None => universe.EmptyTree
+ if (!silent) {
+ val err = context.firstError
+ val errPos = err.map(_.errPos).getOrElse(pos)
+ val errMsg = err.map(_.errMsg).getOrElse("implicit search has failed. to find out the reason, turn on -Xlog-implicits")
+ throw new TypecheckException(errPos, errMsg)
}
+ universe.EmptyTree
case success =>
success.tree
}
@@ -183,12 +183,10 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
trace("inferring implicit %s (macros = %s): ".format(if (isView) "view" else "value", !withMacrosDisabled))(showAttributed(pt, true, true, settings.Yshowsymkinds.value))
val context = currentTyper.context
val result = analyzer.inferImplicit(tree, pt, reportAmbiguous = true, isView = isView, context = context, saveAmbiguousDivergent = !silent, pos = pos)
- if (result.isFailure) {
- // @H: what's the point of tracing an empty tree?
- trace("implicit search has failed. to find out the reason, turn on -Xlog-implicits: ")(result.tree)
- context.firstError foreach { err =>
- throw ToolBoxError("reflective implicit search has failed: %s".format(err.errMsg))
- }
+ if (result.isFailure && !silent) {
+ val err = context.firstError
+ val errMsg = err.map(_.errMsg).getOrElse("reflective implicit search has failed. to find out the reason, turn on -Xlog-implicits")
+ throw ToolBoxError(errMsg)
}
result.tree
})
No changes.
@@ -0,0 +1,19 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+class Foo
+
+object Macros {
+ def impl(c: Context) = {
+ import c.universe._
+ try {
+ c.inferImplicitValue(typeOf[Foo], silent = false)
+ c.abort(c.enclosingPosition, "silent=false is not working")
+ } catch {
+ case _: Exception =>
+ }
+ c.literalNull
+ }
+
+ def foo = macro impl
+}
@@ -0,0 +1,3 @@
+object Test extends App {
+ Macros.foo
+}

0 comments on commit b153880

Please sign in to comment.