autowire icon indicating copy to clipboard operation
autowire copied to clipboard

issues with accessor methods

Open oyvindberg opened this issue 9 years ago • 7 comments

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

oyvindberg avatar Jun 21 '15 22:06 oyvindberg

Agree, there is bug for trait with an accessor method (no parameters) that causes compile error.

bkkoo avatar Jun 29 '15 08:06 bkkoo

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 }

bkkoo avatar Jun 29 '15 08:06 bkkoo

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.

oyvindberg avatar Jun 29 '15 16:06 oyvindberg

So i had a quick look at the macro behind this, and it seems it doesnt work because autowire treats vals 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
}

oyvindberg avatar Jul 02 '15 18:07 oyvindberg

@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.

bkkoo avatar Jul 08 '15 00:07 bkkoo

@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...

lihaoyi avatar Jul 08 '15 03:07 lihaoyi

I believe this commit solves this issue

marcgrue avatar May 19 '20 09:05 marcgrue