codingwell / scala-guice

Scala extensions for Google Guice
Apache License 2.0
341 stars 44 forks source link

Duplicate Binding: ScalaModule believes A == A with B. #43

Open nbauernfeind opened 9 years ago

nbauernfeind commented 9 years ago

@ShengC Provided an example that involves a binding error when it probably shouldn't be.

trait A { def a {} }
trait B

type AB = A with B

class Model extends AbstractModule with ScalaModule {
    def configure() {
        bind[A].toInstance(new A {})
        bind[AB].toInstance(new A with B {})
    }
}

Guice.createInjector(new Model()) // This fails at run time. Guice thinks binds are dups.
tsuckow commented 6 years ago

This could get interesting because AFAICT there is no Java type to represent a mixin. Scala appears to call this a "refined type".

Now, I am not sure if Guice actually cares about the iternals of the type or if we could make up a new class that extends Java.lang.reflect.type and call it a day.