Dagger2 modules with mixed scopes
<p>I am currently trying to set up dagger2 with a custom scope using subcomponents and I am having some trouble with the dagger compiler. More concretely, I have the following setup:</p>

<pre><code>  @Qualifier @interface Foo {}
  @Qualifier @interface Baz {}
  @Scope @interface SomeScope {}

  @Module
  static class Amodule {
    @Provides
    @SomeScope
    @Foo
    String provideFoo(@Baz String baz) {
      return "foo" + baz;
    }

    @Provides
    @Baz
    String provideBaz() {
      return "baz";
    }
  }

  @Component(modules = Amodule.class)
  interface Acomponent {  
    @Baz String baz();
    Subcomp subcomp();
  }

  @SomeScope
  @Subcomponent
  interface Subcomp {
    @Foo String foo();
  }
</code></pre>

<p>Unfortunately, this is giving me the error:</p>

<pre><code>Acomponent (unscoped) may not reference scoped bindings:
  @Component(modules = AModule.class)
  ^
      @Provides @SomeScope @Foo String Amodule.provideFoo(@Baz String)
</code></pre>

<p>I have managed to get things to work by splitting all the custom-scope bindings into a separate module, but I'm not sure why the setup above should not be possible. Also, in my case, the Foo and Baz objects are closely related, so I'd rather not split them into separate modules if it can be avoided.</p>

<p>Can anyone shed some light as to why the dagger compiler won't accept the example above? It seems like inside an <code>@SomeScope</code> subcomponent should be a valid place to expose a binding for <code>@Foo</code>. Am I misunderstanding something or could this be a limitation of the way the codegen is done?</p>

<p>Thanks</p>