Permalink
Browse files

c.typeCheck(silent = true) now suppresses ambiguous errors

Otherwise use cases like the one shown in the attached test (trying to
typecheck something, which leads to an ambiguous overload error) will
mysteriously fail compilation.
  • Loading branch information...
1 parent 5c77e01 commit 658d90ace0068547d89ed398c6775d8cc8264ee0 @xeno-by xeno-by committed May 9, 2013
@@ -22,7 +22,7 @@ trait Typers {
// typechecking uses silent anyways (e.g. in typedSelect), so you'll only waste your time
// I'd advise fixing the root cause: finding why the context is not set to report errors
// (also see reflect.runtime.ToolBoxes.typeCheckExpr for a workaround that might work for you)
- wrapper(callsiteTyper.silent(_.typed(tree, universe.analyzer.EXPRmode, pt)) match {
+ wrapper(callsiteTyper.silent(_.typed(tree, universe.analyzer.EXPRmode, pt), reportAmbiguousErrors = false) match {
case universe.analyzer.SilentResultValue(result) =>
macroLogVerbose(result)
result
@@ -166,7 +166,7 @@ abstract class ToolBoxFactory[U <: JavaUniverse](val u: U) { factorySelf =>
transformDuringTyper(expr, withImplicitViewsDisabled = withImplicitViewsDisabled, withMacrosDisabled = withMacrosDisabled)(
(currentTyper, expr) => {
trace("typing (implicit views = %s, macros = %s): ".format(!withImplicitViewsDisabled, !withMacrosDisabled))(showAttributed(expr, true, true, settings.Yshowsymkinds.value))
- currentTyper.silent(_.typed(expr, analyzer.EXPRmode, pt)) match {
+ currentTyper.silent(_.typed(expr, analyzer.EXPRmode, pt), reportAmbiguousErrors = false) match {
case analyzer.SilentResultValue(result) =>
trace("success: ")(showAttributed(result, true, true, settings.Yshowsymkinds.value))
result
No changes.
@@ -0,0 +1,13 @@
+import scala.reflect.macros.Context
+import language.experimental.macros
+
+object Macros {
+ def impl(c: Context) = {
+ import c.universe._
+ val wut = c.typeCheck(Select(Literal(Constant(10)), newTermName("$minus")), silent = true)
+ // println(showRaw(wut, printIds = true, printTypes = true))
+ c.literalUnit
+ }
+
+ def foo = macro impl
+}
@@ -0,0 +1,3 @@
+class C {
+ def foo = Macros.foo
+}

0 comments on commit 658d90a

Please sign in to comment.