Repository: yandex/yatagan (kotlin)

Issue:
Give a specific error message when including `object` modues into builder
As of now the message is generic and a bit misleading:
```
Extra/unneeded module instance is present
  NOTE: The module doesn't declare any bindings that require module instance
```
And thus can confuse.

Pull request description:
Fixes #5.

Patch:
diff --git a/core/model/impl/src/main/kotlin/ComponentFactoryModelImpl.kt b/core/model/impl/src/main/kotlin/ComponentFactoryModelImpl.kt
index f3f29adc..91e7bf8a 100644
--- a/core/model/impl/src/main/kotlin/ComponentFactoryModelImpl.kt
+++ b/core/model/impl/src/main/kotlin/ComponentFactoryModelImpl.kt
@@ -34,6 +34,7 @@ import com.yandex.yatagan.lang.Parameter
 import com.yandex.yatagan.lang.Type
 import com.yandex.yatagan.lang.TypeDeclaration
 import com.yandex.yatagan.lang.TypeDeclarationKind
+import com.yandex.yatagan.lang.isKotlinObject
 import com.yandex.yatagan.validation.MayBeInvalid
 import com.yandex.yatagan.validation.Validator
 import com.yandex.yatagan.validation.format.Strings
@@ -225,7 +226,11 @@ internal class ComponentFactoryModelImpl private constructor(
                         addNote(Strings.Notes.undeclaredModulePresent())
                     } else {
                         assert(!module.requiresInstance)
-                        addNote(Strings.Notes.moduleDoesNotRequireInstance())
+                        if (module.type.declaration.isKotlinObject) {
+                            addNote(Strings.Notes.objectModuleInBuilder())
+                        } else {
+                            addNote(Strings.Notes.moduleDoesNotRequireInstance())
+                        }
                     }
                 }
             }
diff --git a/validation/format/src/main/kotlin/Strings.kt b/validation/format/src/main/kotlin/Strings.kt
index 563fd22b..f9933a7d 100644
--- a/validation/format/src/main/kotlin/Strings.kt
+++ b/validation/format/src/main/kotlin/Strings.kt
@@ -543,6 +543,12 @@ object Strings {
         fun undeclaredModulePresent() =
             "The module is undeclared, i. m. not present in @Component(.., module = [<here>], ..)".toNote()
 
+        @Covered
+        fun objectModuleInBuilder() =
+            ("The module is a Kotlin `object` - no need to provide it explicitly, " +
+                    "remove it from component creator").toNote()
+
+        @Covered
         fun moduleDoesNotRequireInstance() =
             "The module doesn't declare any bindings that require module instance".toNote()
 


Test patch:
diff --git a/testing/tests/src/test/kotlin/ComponentCreatorFailureTest.kt b/testing/tests/src/test/kotlin/ComponentCreatorFailureTest.kt
index 9a9d86ba..b27ae39a 100644
--- a/testing/tests/src/test/kotlin/ComponentCreatorFailureTest.kt
+++ b/testing/tests/src/test/kotlin/ComponentCreatorFailureTest.kt
@@ -134,7 +134,13 @@ class ComponentCreatorFailureTest(
             @Module
             interface Unnecessary
             
-            @Component
+            @Module
+            class NoBindings
+            
+            @Module
+            object ObjectModule
+            
+            @Component(modules = [ObjectModule::class, NoBindings::class])
             interface MyComponent {
                 @Component.Builder
                 interface Foo : FooBase {
@@ -143,6 +149,8 @@ class ComponentCreatorFailureTest(
                     @BindsInstance fun setDouble(i: Double): Foo
                     fun setString(@BindsInstance i: String): String
                     fun setModule(m: Unnecessary)
+                    fun setModule2(m: ObjectModule)
+                    fun setModule3(m: NoBindings)
                     fun create()
                 }
             
diff --git a/testing/tests/src/test/resources/golden/ComponentCreatorFailureTest/invalid-component-creator.golden.txt b/testing/tests/src/test/resources/golden/ComponentCreatorFailureTest/invalid-component-creator.golden.txt
index 11ae593f..a00a115d 100644
--- a/testing/tests/src/test/resources/golden/ComponentCreatorFailureTest/invalid-component-creator.golden.txt
+++ b/testing/tests/src/test/resources/golden/ComponentCreatorFailureTest/invalid-component-creator.golden.txt
@@ -5,6 +5,28 @@ Encountered:
         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 
+error: Extra/unneeded module instance is present
+NOTE: The module doesn't declare any bindings that require module instance
+Encountered:
+  in graph for root-component test.MyComponent
+  in component-creator test.MyComponent.Foo
+  in creator-setter setModule3(m: test.NoBindings): void
+                               ^-[*1]------------
+  here: [1*] input module test.NoBindings
+             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+error: Extra/unneeded module instance is present
+NOTE: The module is a Kotlin `object` - no need to provide it explicitly, remove it from component creator
+Encountered:
+  in graph for root-component test.MyComponent
+  in component-creator test.MyComponent.Foo
+  in creator-setter setModule2(m: test.ObjectModule): void
+                               ^-[*1]--------------
+  here: [1*] input module test.ObjectModule
+             ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
 error: Extra/unneeded module instance is present
 NOTE: The module is undeclared, i. m. not present in @Component(.., module = [<here>], ..)
 Encountered: