Skip to content

Commit ca9a404

Browse files
garabaisDagger Team
authored andcommitted
Add unit test for parameterized @AssistedFactory with inaccessible type arguments.
This test reproduces compilation failures when using a generic @AssistedFactory interface across package boundaries with package-private type arguments (e.g. Foo.Factory<PackagePrivateBar>). RELNOTES=N/A PiperOrigin-RevId: 956106240
1 parent 13241a9 commit ca9a404

1 file changed

Lines changed: 63 additions & 0 deletions

File tree

javatests/dagger/internal/codegen/AssistedFactoryTest.java

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -543,4 +543,67 @@ public void testAssistedFactoryFromLibraryWithoutProcessor() {
543543
});
544544
}
545545
}
546+
547+
@Test
548+
public void testPublicGenericAssistedFactoryWithPackagePrivateTypeArguments() {
549+
Source foo =
550+
CompilerTests.javaSource(
551+
"pkg.a.Foo",
552+
"package pkg.a;",
553+
"",
554+
"import dagger.assisted.Assisted;",
555+
"import dagger.assisted.AssistedFactory;",
556+
"import dagger.assisted.AssistedInject;",
557+
"",
558+
"public class Foo<T> {",
559+
" @AssistedInject",
560+
" Foo(@Assisted T arg) {}",
561+
"",
562+
" @AssistedFactory",
563+
" public interface Factory<T> {",
564+
" Foo<T> create(T arg);",
565+
" }",
566+
"}");
567+
568+
Source bar =
569+
CompilerTests.javaSource(
570+
"pkg.b.PackagePrivateBar", "package pkg.b;", "", "class PackagePrivateBar {}");
571+
572+
Source client =
573+
CompilerTests.javaSource(
574+
"pkg.b.Client",
575+
"package pkg.b;",
576+
"",
577+
"import javax.inject.Inject;",
578+
"import pkg.a.Foo;",
579+
"",
580+
"public class Client {",
581+
" @Inject",
582+
" Client(Foo.Factory<PackagePrivateBar> factory) {}",
583+
"}");
584+
585+
Source component =
586+
CompilerTests.javaSource(
587+
"test.TestComponent",
588+
"package test;",
589+
"",
590+
"import dagger.Component;",
591+
"import pkg.b.Client;",
592+
"",
593+
"@Component",
594+
"interface TestComponent {",
595+
" Client getClient();",
596+
"}");
597+
598+
CompilerTests.DaggerCompiler daggerCompiler =
599+
CompilerTests.daggerCompiler(foo, bar, client, component)
600+
.withProcessingOptions(compilerMode.processorOptions());
601+
602+
// TODO(b/532992111): Fix javac visibility errors when using generic @AssistedFactory interfaces
603+
// across packages with package-private type arguments.
604+
daggerCompiler.compile(
605+
subject -> {
606+
subject.hasErrorContaining("PackagePrivateBar");
607+
});
608+
}
546609
}

0 commit comments

Comments
 (0)