diff --git a/java/dagger/internal/codegen/binding/ComponentDeclarations.java b/java/dagger/internal/codegen/binding/ComponentDeclarations.java index 1125355ea12..b885da19059 100644 --- a/java/dagger/internal/codegen/binding/ComponentDeclarations.java +++ b/java/dagger/internal/codegen/binding/ComponentDeclarations.java @@ -79,7 +79,12 @@ ImmutableSet bindings(Key key) { ImmutableSet delegates(Key key) { // @Binds @IntoMap declarations have key Map but may be requested as // Map> keys, so unwrap the multibinding map contribution key first. - return delegates.get(keyFactory.unwrapMapValueType(key)); + return delegates.get( + key.multibindingContributionIdentifier().isPresent() + // TODO(bcorso): Consider using TypeNameKey here instead of Key, to avoid losing + // variance information when unwrapping KSP types (see TypeNameKey's javadoc). + ? keyFactory.unwrapMapValueType(key) + : key); } /** diff --git a/javatests/dagger/internal/codegen/BindsMethodValidationTest.java b/javatests/dagger/internal/codegen/BindsMethodValidationTest.java index faf98b951a8..7806b2262fa 100644 --- a/javatests/dagger/internal/codegen/BindsMethodValidationTest.java +++ b/javatests/dagger/internal/codegen/BindsMethodValidationTest.java @@ -16,11 +16,9 @@ package dagger.internal.codegen; -import static com.google.common.truth.Truth.assertThat; import static dagger.internal.codegen.DaggerModuleMethodSubject.Factory.assertThatMethodInUnannotatedClass; import static dagger.internal.codegen.DaggerModuleMethodSubject.Factory.assertThatModuleMethod; import static java.lang.annotation.RetentionPolicy.RUNTIME; -import static org.junit.Assert.assertThrows; import androidx.room.compiler.processing.XProcessingEnv; import androidx.room.compiler.processing.util.Source; @@ -436,20 +434,12 @@ public void bindsMapKVAndRequestMapKProviderV_failsWithMissingBindingError() { "@Qualifier @interface TestQualifier {}"); Source k = CompilerTests.javaSource("test.K", "package test;", "interface K {}"); Source v = CompilerTests.javaSource("test.V", "package test;", "interface V {}"); - // TODO(b/370367984): Once this bug is fixed, no exception should be thrown. - RuntimeException expectedException = - assertThrows( - RuntimeException.class, - () -> CompilerTests.daggerCompiler(component, module, qualifier, k, v) - .compile(subject -> {})); - assertThat(expectedException) - .hasMessageThat() - .contains( - "no expression found for BindingRequest{" - + "key=java.util.Map>, " - + "requestKind=INSTANCE, " - + "frameworkType=Optional.empty" - + "}"); + CompilerTests.daggerCompiler(component, module, qualifier, k, v) + .compile( + subject -> { + subject.hasErrorCount(1); + subject.hasErrorContaining("Map> cannot be provided"); + }); } private DaggerModuleMethodSubject assertThatMethod(String method) {