diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/compiler/scala/reflect/macros/runtime/Typers.scala | 10 | ||||
-rw-r--r-- | src/compiler/scala/reflect/reify/Taggers.scala | 6 | ||||
-rw-r--r-- | src/reflect/scala/reflect/macros/Typers.scala | 26 |
3 files changed, 19 insertions, 23 deletions
diff --git a/src/compiler/scala/reflect/macros/runtime/Typers.scala b/src/compiler/scala/reflect/macros/runtime/Typers.scala index 9fa8567ada..be70181126 100644 --- a/src/compiler/scala/reflect/macros/runtime/Typers.scala +++ b/src/compiler/scala/reflect/macros/runtime/Typers.scala @@ -25,7 +25,7 @@ trait Typers { result case error @ universe.analyzer.SilentTypeError(_) => macroLogVerbose(error.err.errMsg) - if (!silent) throw new universe.TypeError(error.err.errPos, error.err.errMsg) + if (!silent) throw new TypecheckException(error.err.errPos, error.err.errMsg) universe.EmptyTree }) } @@ -49,19 +49,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") - if (context.hasErrors) throw new universe.TypeError(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) + if (context.hasErrors) throw new TypecheckException(context.errBuffer.head.errPos, context.errBuffer.head.errMsg) universe.EmptyTree case success => success.tree } } - type TypeError = universe.TypeError - - object TypeError extends TypeErrorExtractor { - def unapply(error: TypeError): Option[(Position, String)] = Some((error.pos, error.msg)) - } - def resetAllAttrs(tree: Tree): Tree = universe.resetAllAttrs(tree) def resetLocalAttrs(tree: Tree): Tree = universe.resetLocalAttrs(tree) diff --git a/src/compiler/scala/reflect/reify/Taggers.scala b/src/compiler/scala/reflect/reify/Taggers.scala index 7db6394734..513ce020cc 100644 --- a/src/compiler/scala/reflect/reify/Taggers.scala +++ b/src/compiler/scala/reflect/reify/Taggers.scala @@ -1,6 +1,6 @@ package scala.reflect.reify -import scala.reflect.macros.{ReificationError, UnexpectedReificationError} +import scala.reflect.macros.{ReificationError, UnexpectedReificationError, TypecheckException} import scala.reflect.macros.runtime.Context abstract class Taggers { @@ -65,13 +65,13 @@ abstract class Taggers { translatingReificationErrors(materializer) } try c.typeCheck(result) - catch { case terr @ c.TypeError(pos, msg) => failTag(result, terr) } + catch { case terr @ TypecheckException(pos, msg) => failTag(result, terr) } } def materializeExpr(universe: Tree, mirror: Tree, expr: Tree): Tree = { val result = translatingReificationErrors(c.reifyTree(universe, mirror, expr)) try c.typeCheck(result) - catch { case terr @ c.TypeError(pos, msg) => failExpr(result, terr) } + catch { case terr @ TypecheckException(pos, msg) => failExpr(result, terr) } } private def translatingReificationErrors(materializer: => Tree): Tree = { diff --git a/src/reflect/scala/reflect/macros/Typers.scala b/src/reflect/scala/reflect/macros/Typers.scala index eef6507418..9c4854f89f 100644 --- a/src/reflect/scala/reflect/macros/Typers.scala +++ b/src/reflect/scala/reflect/macros/Typers.scala @@ -24,11 +24,11 @@ trait Typers { * Unlike `enclosingImplicits`, this is a def, which means that it gets recalculated on every invocation, * so it might change depending on what is going on during macro expansion. */ - def openImplicits: List[(Type, Tree)] + def openImplicits: List[(Type, Tree)] /** Typechecks the provided tree against the expected type `pt` in the macro callsite context. * - * If `silent` is false, `TypeError` will be thrown in case of a typecheck error. + * If `silent` is false, `TypecheckException` will be thrown in case of a typecheck error. * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Ymacro-debug-verbose. * Unlike in `inferImplicitValue` and `inferImplicitView`, `silent` is false by default. @@ -36,26 +36,32 @@ trait Typers { * Typechecking can be steered with the following optional parameters: * `withImplicitViewsDisabled` recursively prohibits implicit views (though, implicit vals will still be looked up and filled in), default value is false * `withMacrosDisabled` recursively prohibits macro expansions and macro-based implicits, default value is false + * + * @throws [[scala.reflect.macros.TypecheckException]] */ def typeCheck(tree: Tree, pt: Type = WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree /** Infers an implicit value of the expected type `pt` in the macro callsite context. * Optional `pos` parameter provides a position that will be associated with the implicit search. * - * If `silent` is false, `TypeError` will be thrown in case of an inference error. + * If `silent` is false, `TypecheckException` will be thrown in case of an inference error. * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. * Unlike in `typeCheck`, `silent` is true by default. + * + * @throws [[scala.reflect.macros.TypecheckException]] */ def inferImplicitValue(pt: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree /** Infers an implicit view from the provided tree `tree` of the type `from` to the type `to` in the macro callsite context. * Optional `pos` parameter provides a position that will be associated with the implicit search. * - * If `silent` is false, `TypeError` will be thrown in case of an inference error. + * If `silent` is false, `TypecheckException` will be thrown in case of an inference error. * If `silent` is true, the typecheck is silent and will return `EmptyTree` if an error occurs. * Such errors don't vanish and can be inspected by turning on -Xlog-implicits. * Unlike in `typeCheck`, `silent` is true by default. + * + * @throws [[scala.reflect.macros.TypecheckException]] */ def inferImplicitView(tree: Tree, from: Type, to: Type, silent: Boolean = true, withMacrosDisabled: Boolean = false, pos: Position = enclosingPosition): Tree @@ -72,12 +78,8 @@ trait Typers { * For more info, read up https://issues.scala-lang.org/browse/SI-5464. */ def resetLocalAttrs(tree: Tree): Tree +} - /** Represents an error during typechecking - */ - type TypeError <: Throwable - val TypeError: TypeErrorExtractor - abstract class TypeErrorExtractor { - def unapply(error: TypeError): Option[(Position, String)] - } -}
\ No newline at end of file +/** Indicates an error during one of the methods in [[scala.reflect.macros.Typers]]. + */ +case class TypecheckException(val pos: scala.reflect.api.Position, val msg: String) extends Exception(msg) |