- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
synthesised code visible from java but not scala
Mon, 2009-09-14, 21:55
Reposting this as (according to gmane) my original post didn't seem to make the list:http://news.gmane.org/gmane.comp.lang.scala.internals
I have a compiler plugin that runs after typer and synthesizes a method, the method doesn't override from an inherited class or trait. This method can be called from java and behaves correctly, but it's not visible from Scala code.
How can I ensure that my method is added to the scala signature for the generated class file?
As a reference I've used SyntheticMethods (which generates the synthetic methods used by case classes) and I'm sure that I've duplicated all the required behaviour from there.
The difference between my plugin and case classes is that, in case classes, the synthesized methods already exist on the inherited scala.Product trait and are being overridden. This means that even without the synthesized methods it would still be legal to call equals, canEqual, hashCode and toString, they just wouldn't do the Right Thing™
Following this train of thought I'm now looking at how copy and apply are handled for the case class companion object. There's some voodoo going on in namers so that these can be created before typers does its stuff and I'm guessing that something in one of these two phases is involved in generating the scala signature.
I'm also concerned that I may be causing problems by cloning the symbol for the new method (by calling: existing cloneSymbol newOwner) instead of using symbol.newMethod, although nothing in the source code suggests that this should be an issue.
The compiler internals videos on scala-lang have been a big help, but these sadly begin just after the subject of types was covered...
I have a compiler plugin that runs after typer and synthesizes a method, the method doesn't override from an inherited class or trait. This method can be called from java and behaves correctly, but it's not visible from Scala code.
How can I ensure that my method is added to the scala signature for the generated class file?
As a reference I've used SyntheticMethods (which generates the synthetic methods used by case classes) and I'm sure that I've duplicated all the required behaviour from there.
The difference between my plugin and case classes is that, in case classes, the synthesized methods already exist on the inherited scala.Product trait and are being overridden. This means that even without the synthesized methods it would still be legal to call equals, canEqual, hashCode and toString, they just wouldn't do the Right Thing™
Following this train of thought I'm now looking at how copy and apply are handled for the case class companion object. There's some voodoo going on in namers so that these can be created before typers does its stuff and I'm guessing that something in one of these two phases is involved in generating the scala signature.
I'm also concerned that I may be causing problems by cloning the symbol for the new method (by calling: existing cloneSymbol newOwner) instead of using symbol.newMethod, although nothing in the source code suggests that this should be an issue.
The compiler internals videos on scala-lang have been a big help, but these sadly begin just after the subject of types was covered...