Skip to content

"MissingBinding" error when a type is injected as both nullable and non-nullable #1729

@Egorand

Description

@Egorand

Description

This seems to be a regression in 0.10.1: if a type has both nullable and non-nullable injection sites, compilation will fail with the following error:

error: [Metro/MissingBinding] Cannot find an @Inject constructor or @Provides-annotated function/property for: Foo

    Foo is injected at
        [AppGraph] View1(…, foo)
    View1 is requested at
        [AppGraph] AppGraph.view1

Similar bindings:
  - Foo? (Nullable equivalent). Type: ConstructorInjected. Source: NullableNonNullableInject.kt:3:1

Self-contained Reproducer

class Foo @Inject constructor()

class View1 @Inject constructor(foo: Foo)
class View2 @Inject constructor(foo: Foo?)

@DependencyGraph
interface AppGraph {
  val view1: View1
  val view2: View2
}

fun box(): String {
  val graph = createGraph<AppGraph>()
  val view1 = graph.view1
  val view2 = graph.view2
  return "OK"
}

Metro version

0.10.1

Context

Initially reproduced in cash-android, and was later reproduced in the metro repo with a unit test.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions