diff options
author | Jason Zaugg <jzaugg@gmail.com> | 2014-11-07 11:10:15 +1000 |
---|---|---|
committer | Jason Zaugg <jzaugg@gmail.com> | 2014-11-07 11:10:15 +1000 |
commit | 7830b4689a5f9962011f117c9b866a939795e58a (patch) | |
tree | cc3e0a2bbf67d350775d44dbe648ea2e37451c1c /test/files/pos | |
parent | 000de44e3b1f1c0c4bc30eda8ef155548714a6af (diff) | |
parent | 17992f672f7d5663654a1ea365dfd1dad7061410 (diff) | |
download | scala-7830b4689a5f9962011f117c9b866a939795e58a.tar.gz scala-7830b4689a5f9962011f117c9b866a939795e58a.tar.bz2 scala-7830b4689a5f9962011f117c9b866a939795e58a.zip |
Merge pull request #4083 from retronym/ticket/8947
SI-8947 Avoid cross talk between tag materializers and reify
Diffstat (limited to 'test/files/pos')
-rw-r--r-- | test/files/pos/t8947/Client_2.scala | 1 | ||||
-rw-r--r-- | test/files/pos/t8947/Macro_1.scala | 41 |
2 files changed, 42 insertions, 0 deletions
diff --git a/test/files/pos/t8947/Client_2.scala b/test/files/pos/t8947/Client_2.scala new file mode 100644 index 0000000000..1a5082a2f9 --- /dev/null +++ b/test/files/pos/t8947/Client_2.scala @@ -0,0 +1 @@ +object Test { X.extractor }
\ No newline at end of file diff --git a/test/files/pos/t8947/Macro_1.scala b/test/files/pos/t8947/Macro_1.scala new file mode 100644 index 0000000000..4a5de3decb --- /dev/null +++ b/test/files/pos/t8947/Macro_1.scala @@ -0,0 +1,41 @@ +import language.experimental.macros +import scala.reflect.macros._ +import blackbox.Context + +object X { + + def classTagOrNull[T](implicit t: reflect.ClassTag[T] = null) = t + // the failed search for ClassTag[T] does not issue a visible + // error as we fall back to the default argument. But, the + // macro engine things we have expanded the macro `materializeClassTag[D]()` + // to `EmptyTree`, and then attaches a backreference from the expansion + // to the expandee. This is the `MacroExpansionAttachment` tree attachment. + def foo[D] = classTagOrNull[D] + + def extractor: Any = macro X.extractorMacro + def extractorMacro(c: Context): c.Expr[Any] = { + // Later, in reify, an unrelated use of `EmptyTree` in the AST representing + // the argument is now treated as a macro expansion which should be rolled + // back in the tree we reify! This ends up generating a call to `implicitly` + // which leads to an ambiguous error. + // + // Any macro call that expands to EmptyTree could have triggered this problem. + c.universe.reify(new { def something(data: Any) = ??? }) + } + + // Workarounds: + // + // 1. Use quasiquotes rather than `reify`. (But, beware to fully qualify all references, e.g. `_root_.scala.Predef.???`) + // 2. Avoid failed ClassTag lookups (e.g. in the original bug report, annotate the type argument to `map`) + // 3. In the macro implementation, just before calling the `reify` macro, you could call another macro + // + // def prepareReify = macro prepareReifyImpl + // def prepareReifyImpl(c: Context) = { + // val symtab = c.universe.asInstanceOf[reflect.internal.SymbolTable] + // symtab.EmptyTree.setAttachments(symtab.NoPosition) + // } + // + // To make this visible to the macro implementaiton, it will need to be compiled in an earlier stage, + // e.g a separate SBT sub-project. + +} |