I would like to add a static field (called bar in this example) to a class (named Foo ) with a type macro (named Static ).
Here's how I'm trying to do it now:
Macro
import language.experimental.macros import scala.reflect.macros.Context package object statics { type Static = macro Statics.addStaticField object Statics { def addStaticField(c: Context): c.Tree = { import c.universe._ val STATIC = 1 << 23 type CompilerSymbol = scala.tools.nsc.Global
At compile time, calling setFlag seems to have an effect because the flag string changes:
Flags: Setting flag ... Flags: <static>
But it looks like it has almost no effect on the usage site:
package statics class Foo extends Static object Main extends App { Foo.bar
show and showRaw also do not display Static characters.
How can I solve this problem?
source share