summaryrefslogtreecommitdiff
path: root/src/reflect/scala/reflect/macros/Typers.scala
diff options
context:
space:
mode:
authorEugene Burmako <xeno.by@gmail.com>2014-01-29 18:15:31 +0300
committerEugene Burmako <xeno.by@gmail.com>2014-02-14 14:19:44 +0100
commit2c05f0139758613fbe26a5c03d60a9da29f2f5e5 (patch)
tree7c64843ff5137539172fee6106282b8b7bda94e9 /src/reflect/scala/reflect/macros/Typers.scala
parent0268e03cb461b0c7e8ae2082894988395fc0994a (diff)
downloadscala-2c05f0139758613fbe26a5c03d60a9da29f2f5e5.tar.gz
scala-2c05f0139758613fbe26a5c03d60a9da29f2f5e5.tar.bz2
scala-2c05f0139758613fbe26a5c03d60a9da29f2f5e5.zip
SI-6814 adds typechecker modes to c.typecheck
As per multiple user requests, this commit introduces a shortcut to typecheck trees under multiple different modes: terms (EXPRmode, was exposed in Scala 2.10) and types (TYPEmode). Looking into the rest of a dozen of internal typechecker modes, to the best of my knowledge, I can’t find other modes that we could expose. FUNmode is useful, but very situational. PATTERNmode is useful, but also situational, because we don’t expand macros inside patterns except for whitebox extractor macros. The rest (e.g. POLYmode or TAPPmode) are too low-level.
Diffstat (limited to 'src/reflect/scala/reflect/macros/Typers.scala')
-rw-r--r--src/reflect/scala/reflect/macros/Typers.scala34
1 files changed, 31 insertions, 3 deletions
diff --git a/src/reflect/scala/reflect/macros/Typers.scala b/src/reflect/scala/reflect/macros/Typers.scala
index 6c077de1d2..f1d8575774 100644
--- a/src/reflect/scala/reflect/macros/Typers.scala
+++ b/src/reflect/scala/reflect/macros/Typers.scala
@@ -2,6 +2,8 @@ package scala
package reflect
package macros
+import scala.reflect.internal.{Mode => InternalMode}
+
/**
* <span class="badge badge-red" style="float: right;">EXPERIMENTAL</span>
*
@@ -23,13 +25,39 @@ trait Typers {
*/
def openMacros: List[blackbox.Context]
+ /** Represents mode of operations of the typechecker underlying `c.typecheck` calls.
+ * Is necessary since the shape of the typechecked tree alone is not enough to guess how it should be typechecked.
+ * Can be EXPRmode (typecheck as a term) or TYPEmode (typecheck as a type).
+ */
+ // I'd very much like to make use of https://github.com/dsl-paradise/dsl-paradise here!
+ type TypecheckMode
+
+ /** Indicates that an argument to `c.typecheck` should be typechecked as a term.
+ * This is the default typechecking mode in Scala 2.11 and the only one supported in Scala 2.10.
+ */
+ val TERMmode: TypecheckMode
+
+ /** Indicates that an argument to `c.typecheck` should be typechecked as a type.
+ */
+ val TYPEmode: TypecheckMode
+
+ /** @see `scala.reflect.macros.TypecheckException`
+ */
+ type TypecheckException = scala.reflect.macros.TypecheckException
+
+ /** @see `scala.reflect.macros.TypecheckException`
+ */
+ val TypecheckException = scala.reflect.macros.TypecheckException
+
/** @see `Typers.typecheck`
*/
@deprecated("Use `c.typecheck` instead", "2.11.0")
def typeCheck(tree: Tree, pt: Type = universe.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree =
- typecheck(tree, pt, silent, withImplicitViewsDisabled, withMacrosDisabled)
+ typecheck(tree, TERMmode, pt, silent, withImplicitViewsDisabled, withMacrosDisabled)
- /** Typechecks the provided tree against the expected type `pt` in the macro callsite context.
+ /** Typechecks the provided tree against the expected type `pt` in the macro callsite context
+ * under typechecking mode specified in `mode` with [[EXPRmode]] being default.
+ * This populates symbols and types of the tree and possibly transforms it to reflect certain desugarings.
*
* 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.
@@ -42,7 +70,7 @@ trait Typers {
*
* @throws [[scala.reflect.macros.TypecheckException]]
*/
- def typecheck(tree: Tree, pt: Type = universe.WildcardType, silent: Boolean = false, withImplicitViewsDisabled: Boolean = false, withMacrosDisabled: Boolean = false): Tree
+ def typecheck(tree: Tree, mode: TypecheckMode = TERMmode, pt: Type = universe.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.