diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-01-29 18:15:31 +0300 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-02-14 14:19:44 +0100 |
commit | 2c05f0139758613fbe26a5c03d60a9da29f2f5e5 (patch) | |
tree | 7c64843ff5137539172fee6106282b8b7bda94e9 /test/files/run/t6814 | |
parent | 0268e03cb461b0c7e8ae2082894988395fc0994a (diff) | |
download | scala-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 'test/files/run/t6814')
-rw-r--r-- | test/files/run/t6814/Macros_1.scala | 24 | ||||
-rw-r--r-- | test/files/run/t6814/Test_2.scala | 3 |
2 files changed, 27 insertions, 0 deletions
diff --git a/test/files/run/t6814/Macros_1.scala b/test/files/run/t6814/Macros_1.scala new file mode 100644 index 0000000000..0257f451d6 --- /dev/null +++ b/test/files/run/t6814/Macros_1.scala @@ -0,0 +1,24 @@ +import scala.language.experimental.macros +import scala.reflect.macros.blackbox.Context + +object Macros { + def impl(c: Context) = { + import c.universe._ + + def test(tree: Tree, mode: c.TypecheckMode): String = { + try c.typecheck(tree, mode, silent = false).tpe.toString + catch { case c.TypecheckException(_, msg) => msg } + } + + q""" + println(${test(q"List(1, 2)", c.TERMmode)}) + println(${test(q"List", c.TERMmode)}) + println(${test(q"RuntimeException", c.TERMmode)}) + println(${test(tq"List[Int]", c.TYPEmode)}) + println(${test(tq"List", c.TYPEmode)}) + println(${test(q"List", c.TYPEmode)}) + println(${test(q"List(1, 2)", c.TYPEmode)}) + """ + } + def foo: Unit = macro impl +}
\ No newline at end of file diff --git a/test/files/run/t6814/Test_2.scala b/test/files/run/t6814/Test_2.scala new file mode 100644 index 0000000000..acfddae942 --- /dev/null +++ b/test/files/run/t6814/Test_2.scala @@ -0,0 +1,3 @@ +object Test extends App { + Macros.foo +}
\ No newline at end of file |