autowire
autowire copied to clipboard
issues with accessor methods
I've been doing some scalajs hacking lately, and had a look at autowire the other day. I exported a trait with an accessor method (no parameters), and that made my project stop compiling.
It really took me a while to figure out why, so i made a PR with a failing (that is, doesnt compile) test, so we can work it out. See #35
Agree, there is bug for trait with an accessor method (no parameters) that causes compile error.
Currently, I've to make accessor method with empty parenthesis instead. For example :
trait MyInfo { def myName(): String // that should only be --> def myName:String or val myName:String }
Err, so much for actually reading your comment!
Yes, I figured it was mostly possible to use empty parenthesis so work around the problem, this is mostly a big problem for people experimenting with the library, where it's almost impossible to understand what you're doing wrong - I spent a long while making random changes to my source code in order to figure it out.
So i had a quick look at the macro behind this, and it seems it doesnt work because autowire treats val
s as nested traits with methods to expose (if i understand it correctly).
@lihaoyi would it be a better idea to for example tag traits with an annotation? would you be interested if i tried to hack that into working?
@autowireable
trait {
val x = 42
}
@elacin Sorry for my unclear comment. I do not understand about "autowire treats vals as nested traits with methods to expose" but I'm interested in your workaround by using annotation. I'm not scala macro expert and have no time to learn and dig in to autowire source code. Thank you.
@lihaoyi would it be a better idea to for example tag traits with an annotation? would you be interested if i tried to hack that into working?
I did that before, I didn't find it that useful.
Unfortunately, I don't have time to look at this right now; I'm making my rounds through my various libraries and current focus is on upickle/ammonite. I'll have something more intelligent to say next time...
I believe this commit solves this issue