Permalink
Browse files

[nomaster] SI-7047 fixes silent for c.inferImplicitXXX

silent = true now throws a TypecheckException even if we don't know why
an implicit search has failed (i.e. if context.hasErrors is false).

NOTE: this commit is a part of a pull request for 2.10.x, which makes sense of
implicit macros. Everything in that pull request is [nomaster] due to one
reason or another. This commit would work equally well in both 2.10.x and
master, but I'm marking it as [nomaster] as well, because I'm anyway going
to resubmit the whole pull request into master soon, so there's no reason
to introduce additional confusion.
  • Loading branch information...
1 parent fdead2b commit b4da864247ccaaee4f987fbf433b312e1d744a8f @xeno-by xeno-by committed Feb 23, 2013
@@ -52,7 +52,10 @@ 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")
- if (context.hasErrors) throw new TypecheckException(context.errBuffer.head.errPos, context.errBuffer.head.errMsg)
+ if (!silent) {
+ if (context.hasErrors) throw new TypecheckException(context.errBuffer.head.errPos, context.errBuffer.head.errMsg)
+ else throw new TypecheckException(pos, "implicit search has failed. to find out the reason, turn on -Xlog-implicits")
+ }
universe.EmptyTree
case success =>
success.tree
@@ -185,7 +185,10 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
analyzer.inferImplicit(tree, pt, reportAmbiguous = true, isView = isView, context = context, saveAmbiguousDivergent = !silent, pos = pos) match {
case failure if failure.tree.isEmpty =>
trace("implicit search has failed. to find out the reason, turn on -Xlog-implicits: ")(failure.tree)
- if (context.hasErrors) throw ToolBoxError("reflective implicit search has failed: %s".format(context.errBuffer.head.errMsg))
+ if (!silent) {
+ if (context.hasErrors) throw ToolBoxError("reflective implicit search has failed: %s".format(context.errBuffer.head.errMsg))
+ else throw new ToolBoxError("reflective implicit search has failed. to find out the reason, turn on -Xlog-implicits")
+ }
EmptyTree
case success =>
success.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 b4da864

Please sign in to comment.