square / anvil

A Kotlin compiler plugin to make dependency injection with Dagger 2 easier.
Apache License 2.0
1.32k stars 82 forks source link

generateDaggerFactories fails when module return type is inferred #98

Closed ursusursus closed 4 years ago

ursusursus commented 4 years ago
@AppScope
    @JvmStatic
    @Provides
    fun appSlotsRepository(
        dao: Dao,
        apiClient: ApiClient,
        refreshHelper: RefreshHelper
    ) = AppSlotRepository(apiClient, dao, refreshHelper)
e: com.squareup.anvil.compiler.AnvilCompilationException: Back-end (JVM) Internal error: Couldn't resolve type of function: sk.o2.mojeo2.base.di.DataModule.appSlotsRepository
File being compiled: (186,5) in C:/Users/ursus/AndroidStudioProjects/o2-selfcare-android/legacy/src/main/java/sk/o2/mojeo2/base/di/DataModule.kt

    at com.squareup.anvil.compiler.codegen.KotlinPoetKt$requireTypeName$1.invoke(KotlinPoet.kt:48)
    at com.squareup.anvil.compiler.codegen.KotlinPoetKt.requireTypeName(KotlinPoet.kt:53)
    at com.squareup.anvil.compiler.codegen.KotlinPoetKt.requireTypeName$default(KotlinPoet.kt:46)
    at com.squareup.anvil.compiler.codegen.dagger.ProvidesMethodFactoryGenerator.generateFactoryClass(ProvidesMethodFactoryGenerator.kt:92)
    at com.squareup.anvil.compiler.codegen.dagger.ProvidesMethodFactoryGenerator.access$generateFactoryClass(ProvidesMethodFactoryGenerator.kt:42)
    at com.squareup.anvil.compiler.codegen.dagger.ProvidesMethodFactoryGenerator$generateCode$3$2.invoke(ProvidesMethodFactoryGenerator.kt:58)
    at com.squareup.anvil.compiler.codegen.dagger.ProvidesMethodFactoryGenerator$generateCode$3$2.invoke(ProvidesMethodFactoryGenerator.kt:42)
    at kotlin.sequences.TransformingSequence$iterator$1.next(Sequences.kt:210)
    at kotlin.sequences.FlatteningSequence$iterator$1.next(Sequences.kt:299)
    at kotlin.sequences.SequencesKt___SequencesKt.toCollection(_Sequences.kt:742)
    at kotlin.sequences.SequencesKt___SequencesKt.toMutableList(_Sequences.kt:772)
    at kotlin.sequences.SequencesKt___SequencesKt.toList(_Sequences.kt:763)
    at com.squareup.anvil.compiler.codegen.dagger.ProvidesMethodFactoryGenerator.generateCode(ProvidesMethodFactoryGenerator.kt:61)
    at com.squareup.anvil.compiler.codegen.CodeGenerationExtension$analysisCompleted$2.invoke(CodeGenerationExtension.kt:57)
    at com.squareup.anvil.compiler.codegen.CodeGenerationExtension.analysisCompleted(CodeGenerationExtension.kt:62)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM$analyzeFilesWithJavaIntegration$2.invoke(TopDownAnalyzerFacadeForJVM.kt:108)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration(TopDownAnalyzerFacadeForJVM.kt:118)
    at org.jetbrains.kotlin.cli.jvm.compiler.TopDownAnalyzerFacadeForJVM.analyzeFilesWithJavaIntegration$default(TopDownAnalyzerFacadeForJVM.kt:93)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:526)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler$analyze$1.invoke(KotlinToJVMBytecodeCompiler.kt:90)
    at org.jetbrains.kotlin.cli.common.messages.AnalyzerWithCompilerReport.analyzeAndReport(AnalyzerWithCompilerReport.kt:115)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.analyze(KotlinToJVMBytecodeCompiler.kt:517)
    at org.jetbrains.kotlin.cli.jvm.compiler.KotlinToJVMBytecodeCompiler.compileModules$cli(KotlinToJVMBytecodeCompiler.kt:185)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:164)
    at org.jetbrains.kotlin.cli.jvm.K2JVMCompiler.doExecute(K2JVMCompiler.kt:51)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:86)
    at org.jetbrains.kotlin.cli.common.CLICompiler.execImpl(CLICompiler.kt:44)
    at org.jetbrains.kotlin.cli.common.CLITool.exec(CLITool.kt:98)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:346)
    at org.jetbrains.kotlin.incremental.IncrementalJvmCompilerRunner.runCompiler(IncrementalJvmCompilerRunner.kt:102)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compileIncrementally(IncrementalCompilerRunner.kt:240)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.access$compileIncrementally(IncrementalCompilerRunner.kt:39)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner$compile$2.invoke(IncrementalCompilerRunner.kt:81)
    at org.jetbrains.kotlin.incremental.IncrementalCompilerRunner.compile(IncrementalCompilerRunner.kt:93)
    at org.jetbrains.kotlin.daemon.CompileServiceImplBase.execIncrementalCompiler(CompileServiceImpl.kt:601)
    at org.jetbrains.kotlin.daemon.CompileServiceImplBase.access$execIncrementalCompiler(CompileServiceImpl.kt:93)
    at org.jetbrains.kotlin.daemon.CompileServiceImpl.compile(CompileServiceImpl.kt:1633)
    at sun.reflect.GeneratedMethodAccessor99.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357)
    at sun.rmi.transport.Transport$1.run(Transport.java:200)
    at sun.rmi.transport.Transport$1.run(Transport.java:197)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.Transport.serviceCall(Transport.java:196)
    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688)
    at java.security.AccessController.doPrivileged(Native Method)
    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)

If I declare the return type explicity then it works. Its good do it anyways, however dagger can work throught it without a problem

vRallev commented 4 years ago

See #86 for an explanation.

ursusursus commented 4 years ago

Fair enough, thanks

vRallev commented 4 years ago

We have a KtLint rule that flags this for us. We should really try harder to open source these :(