macwire icon indicating copy to clipboard operation
macwire copied to clipboard

Unclear compilation error using valsByClass

Open asinitsyn opened this issue 11 years ago • 5 comments

I get the following error trying to compile Global.scala for play framework

[error] C:\Trader\app\Global.scala:7: type mismatch; [error] found : Any [error] required: AnyRef [error] val instanceLookup = InstanceLookup(valsByClass(ProdModule)) [error] ^

ProdModule is an object and inherits from other traits. My problem is I cannot understand what causes this error or how to debug it.

asinitsyn avatar Apr 01 '14 18:04 asinitsyn

Looks quite weird :) Can you try splitting InstanceLookup and valsByClass, to see where the type error exactly is? So: val vbc = valsByClass(ProdModule) val instanceLookup = InstanceLookup(vbc)

adamw avatar Apr 02 '14 05:04 adamw

It fails on: [error] val instanceMap = valsByClass(ProdModule)

With some trial and error I localized the line of code in one of the traits that causes it. val connectionsActor = actorSystem.actorOf(Props(wire[ConnectionsActor]), "connections")

when I comment it out compilation works fine, but it still fails even with 'new' instead of wire. This is the case where I don't really need wire macro. val connectionsActor = actorSystem.actorOf(Props(new ConnectionsActor), "connections")

Please, note that actorSystem is defined in another trait that current trait extends from.

asinitsyn avatar Apr 02 '14 16:04 asinitsyn

Weird :) What if you add an explicit type annotation to "connectionsActor"? E.g.:

val connectionsActor: ActorRef = ...

adamw avatar Apr 03 '14 13:04 adamw

Adding ActorRef fixed it. Thanks a lot for your help and MacWire! I really like simplicity of MacWire.

Do you think there is a way to make the cryptic error I ran into less cryptic?

asinitsyn avatar Apr 03 '14 20:04 asinitsyn

Definitely, I don't know yet why exactly this happens, but I'll try :)

adamw avatar Apr 03 '14 20:04 adamw