Skip to content

Handle generic @Inject classes with private constructors #833

@bubenheimer

Description

@bubenheimer

Description

Metro appears to support injecting classes with private constructors, which I am finding useful, thank you!

However, this does not work for generic classes with private constructors, this scenario results in a compiler crash:

genericclassprivateconstructorcompilercrash.txt

The example builds without crash when the constructor is made internal.

My actual use case is assisted injection, but the build crash appears to trigger without those extra bits.

I would like to see:

  1. No compiler crash
  2. Support this variation if possible, for consistency, otherwise generate normal build error.

Self-contained Reproducer

@Inject
class Generic<T> private constructor(value: T)

bubenheimer/metrobugs@6d946ca

Metro version

Current 0.6.0-SNAPSHOT

Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    waiting for upstreamThis issue or PR is dependent on upstream Kotlin compiler changes/fixes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions