diff options
author | Eugene Burmako <xeno.by@gmail.com> | 2014-03-07 14:52:23 +0100 |
---|---|---|
committer | Eugene Burmako <xeno.by@gmail.com> | 2014-03-07 18:56:35 +0100 |
commit | b10f45a78217b002f8ac6e2051ff932a1ac2e029 (patch) | |
tree | fe781db5f7290794ddbec794aa53f2e399f12af8 /test/files/neg/macro-incompatible-macro-engine-a/Plugin_1.scala | |
parent | 2dddb03b267770afcd0249ad700e55d53019e637 (diff) | |
download | scala-b10f45a78217b002f8ac6e2051ff932a1ac2e029.tar.gz scala-b10f45a78217b002f8ac6e2051ff932a1ac2e029.tar.bz2 scala-b10f45a78217b002f8ac6e2051ff932a1ac2e029.zip |
SI-8375 saner binary incompat errors for macros
Inspired by Brian McKenna's RC1 migration experience, this commit improves
macro impl binding validation in order to provide more helpful diagnostic
for this quite frequent class of errors.
Diffstat (limited to 'test/files/neg/macro-incompatible-macro-engine-a/Plugin_1.scala')
-rw-r--r-- | test/files/neg/macro-incompatible-macro-engine-a/Plugin_1.scala | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/files/neg/macro-incompatible-macro-engine-a/Plugin_1.scala b/test/files/neg/macro-incompatible-macro-engine-a/Plugin_1.scala new file mode 100644 index 0000000000..44ed91d2fb --- /dev/null +++ b/test/files/neg/macro-incompatible-macro-engine-a/Plugin_1.scala @@ -0,0 +1,35 @@ +package incompatibleMacroEngine + +import scala.tools.nsc.Global +import scala.tools.nsc.plugins.{Plugin => NscPlugin} + +class Plugin(val global: Global) extends NscPlugin { + import global._ + import analyzer._ + + val name = "incompatibleMacroEngine" + val description = "A sample analyzer plugin that crafts a macro impl binding with a non-standard macro engine." + val components = Nil + addMacroPlugin(MacroPlugin) + + object MacroPlugin extends MacroPlugin { + def fixupBinding(tree: Tree) = new Transformer { + override def transform(tree: Tree) = { + tree match { + case Literal(const @ Constant(x)) if tree.tpe == null => tree setType ConstantType(const) + case _ if tree.tpe == null => tree setType NoType + case _ => ; + } + super.transform(tree) + } + }.transform(tree) + + override def pluginsTypedMacroBody(typer: Typer, ddef: DefDef): Option[Tree] = { + val result = standardTypedMacroBody(typer, ddef) + val List(AnnotationInfo(atp, List(Apply(nucleus, _ :: others)), Nil)) = ddef.symbol.annotations + val updatedBinding = Apply(nucleus, Assign(Literal(Constant("macroEngine")), Literal(Constant("vxxx (implemented in the incompatibleMacroEngine plugin)"))) :: others) + ddef.symbol.setAnnotations(List(AnnotationInfo(atp, List(fixupBinding(updatedBinding)), Nil))) + Some(result) + } + } +}
\ No newline at end of file |