How to build a dynamic sequence in a scala macro?
问题 I have a scala macro which outputs nested case classes. I can assemble fragments of expressions created using reify to build up the nested case classes programmatically: case class Foo(name: String) case class Bar(foo: Foo) def foo(name: String) = { c.universe reify { Foo(c.literal(name).splice) } } def bar(foo: Expr[Foo]) = { c.universe reify { Bar(foo.splice) } } // output Bar(Foo("MyFoo")) c.Expr( bar(foo("MyFoo").asInstanceOf[Expr[Foo]]).tree ) Things work well apart from the annoying