anvil icon indicating copy to clipboard operation
anvil copied to clipboard

Generics typealias codegen error

Open bubenheimer opened this issue 1 year ago • 1 comments

The below kind of typealias usage with a generic generates invalid code in 2.5.0-beta09; not sure if it will build in prior versions:

typealias Alias<T> = Foo<Bar<T>, T> // in a separate file, not sure it matters

class SomeActivity {
    @Inject
    internal lateinit var alias: Alias<Boolean>
}

This generates code like below; note the raw Bar<T>:

public class SomeActivity_MembersInjector(
  private val alias: Provider<@JvmSuppressWildcards Foo<Bar<T>, Boolean>>,
) : MembersInjector<SomeActivity> {
//...
}

Anvil only seems to expand generics at the top level here, not a second-level usage. A typealias like this works fine:

typealias Alias<T> = Foo<Int, T>

bubenheimer avatar Jul 14 '24 01:07 bubenheimer

Behavior unchanged in 2.5.0 release

bubenheimer avatar Dec 10 '24 14:12 bubenheimer