diff --git a/java/dagger/internal/codegen/AssistedFactoryProcessingStep.java b/java/dagger/internal/codegen/AssistedFactoryProcessingStep.java index 32b1019366c..b687b6b18d4 100644 --- a/java/dagger/internal/codegen/AssistedFactoryProcessingStep.java +++ b/java/dagger/internal/codegen/AssistedFactoryProcessingStep.java @@ -160,6 +160,12 @@ ValidationReport validate(TypeElement factory) { methodType.getReturnType()), method); } + if (!method.getTypeParameters().isEmpty()) { + report.addError( + "@AssistedFactory does not currently support type parameters in the creator " + + "method. See https://github.com/google/dagger/issues/2279", + method); + } } if (abstractFactoryMethods.size() > 1) { diff --git a/javatests/dagger/internal/codegen/AssistedFactoryErrorsTest.java b/javatests/dagger/internal/codegen/AssistedFactoryErrorsTest.java index 0c22875342a..ec18cada26e 100644 --- a/javatests/dagger/internal/codegen/AssistedFactoryErrorsTest.java +++ b/javatests/dagger/internal/codegen/AssistedFactoryErrorsTest.java @@ -772,4 +772,34 @@ public void testInaccessibleFoo() { assertThat(compilation).succeeded(); } } + + @Test + public void testAssistedFactoryMethodWithTypeParametersFails() { + JavaFileObject foo = + JavaFileObjects.forSourceLines( + "test.Foo", + "package test;", + "", + "import dagger.assisted.AssistedInject;", + "import dagger.assisted.AssistedFactory;", + "", + "class Foo {", + " @AssistedInject", + " Foo() {}", + "", + " @AssistedFactory", + " interface FooFactory {", + " Foo create();", + " }", + "}"); + + Compilation compilation = compilerWithOptions(compilerMode.javacopts()).compile(foo); + assertThat(compilation).failed(); + assertThat(compilation).hadErrorCount(1); + assertThat(compilation) + .hadErrorContaining( + "@AssistedFactory does not currently support type parameters in the creator method.") + .inFile(foo) + .onLine(12); + } }