I've written a macro annotation processor that generates all the same methods you would get from declaring a case class, but providing hash-consing. It was a bit tricky, but overall I'm very pleased with the results. However, I'm seeing some behavior around the apply
method I have yet to solve.
Previously when a class Foo
was a case class or has a manually defined apply
method I could write code like foos.map(Foo)
. However, now that the method is generated by the macro processor it will complain with an error like the following
type mismatch;
[error] found : Foo.type
[error] required: String => ?
Now I can just rewrite the code as foos.map(Foo.apply)
or foos.map(Foo(_))
and it will work, but I haven't been able to discern any difference in the code that I am generating that would cause this difference in behavior.
I suspect it is something like the Scala compiler is too eagerly resolving the symbol to the type name rather than the object name or some such, but if there is a way to do better here it would be good to know.