diff --git a/java/dagger/internal/codegen/validation/InjectValidator.java b/java/dagger/internal/codegen/validation/InjectValidator.java index f223f6a9a08..6056a849aee 100644 --- a/java/dagger/internal/codegen/validation/InjectValidator.java +++ b/java/dagger/internal/codegen/validation/InjectValidator.java @@ -255,6 +255,13 @@ private ValidationReport validateConstructor(XConstructorElement constructorElem constructorElement); } + if (enclosingElement.isValueClass()) { + builder.addError( + String.format("@%s constructors on Kotlin inline value classes is not supported", + injectAnnotation.simpleName()), + constructorElement); + } + // Note: superficial validation of the annotations is done as part of getting the scopes. ImmutableSet scopes = injectionAnnotations.getScopes(constructorElement.getEnclosingElement()); diff --git a/javatests/dagger/internal/codegen/InjectConstructorFactoryGeneratorTest.java b/javatests/dagger/internal/codegen/InjectConstructorFactoryGeneratorTest.java index bd2886bde2b..5381c8ffcba 100644 --- a/javatests/dagger/internal/codegen/InjectConstructorFactoryGeneratorTest.java +++ b/javatests/dagger/internal/codegen/InjectConstructorFactoryGeneratorTest.java @@ -147,6 +147,27 @@ public final class InjectConstructorFactoryGeneratorTest { }); } + @Test public void injectConstructorOnInlineValueClass() { + Source file = + CompilerTests.kotlinSource( + "test.InlineValueClass.kt", + "package test", + "", + "import javax.inject.Inject;", + "", + "@JvmInline value class InlineValueClass", + " @Inject constructor(private val v: Int)"); + CompilerTests.daggerCompiler(file) + .compile( + subject -> { + subject.hasErrorCount(1); + subject.hasErrorContaining( + "@Inject constructors on Kotlin inline value classes is not supported") + .onSource(file) + .onLine(6); + }); + } + @Test public void fieldAndMethodGenerics() { Source file = CompilerTests.javaSource(