Skip to content

Commit 385c131

Browse files
Jeffsetbacecek
authored andcommitted
[ksp2] Fixes #189
1 parent 791ee3c commit 385c131

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

lang/ksp/src/main/kotlin/KspTypeDeclarationImpl.kt

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,16 +205,27 @@ internal class KspTypeDeclarationImpl private constructor(
205205
filter: FunctionFilter,
206206
isStatic: (KSAnnotated) -> Boolean,
207207
) {
208-
val isPropertyStatic = isStatic(property)
209-
property.getter?.let { getter ->
208+
val refinedProperty = if (
209+
property.getter == null && property.setter == null &&
210+
/* not a java field */ property.isFromKotlin && Utils.isKsp2
211+
) {
212+
// In the cases where the property is overriding multiple identical properties from the supertypes,
213+
// KSP2 returns a property without getter and setter.
214+
// We detect it and try to use `findOverridee()` instead,
215+
// which returns the actual property from one of the bases
216+
property.findOverridee() ?: property
217+
} else property
218+
219+
val isPropertyStatic = isStatic(refinedProperty)
220+
refinedProperty.getter?.let { getter ->
210221
if (filter.filterAccessor(getter)) {
211222
yield(KspPropertyGetterImpl(
212223
owner = owner, getter = getter,
213224
isStatic = isPropertyStatic || isStatic(getter)
214225
))
215226
}
216227
}
217-
property.setter?.let { setter ->
228+
refinedProperty.setter?.let { setter ->
218229
val modifiers = setter.modifiers
219230
if (Modifier.PRIVATE !in modifiers && Modifier.PROTECTED !in modifiers && filter.filterAccessor(setter)) {
220231
yield(KspPropertySetterImpl(

testing/tests/src/test/kotlin/CoreBindingsKotlinTest.kt

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -914,5 +914,28 @@ class CoreBindingsKotlinTest(
914914

915915
compileRunAndValidate()
916916
}
917+
918+
@Test
919+
fun `reproduce #189`() {
920+
givenKotlinSource("test.TestCase", """
921+
import com.yandex.yatagan.*
922+
import javax.inject.*
923+
924+
class TestClass @Inject constructor()
925+
926+
interface Deps1 {
927+
val testClass: TestClass
928+
}
929+
930+
interface Deps2 {
931+
val testClass: TestClass
932+
}
933+
934+
@Component
935+
interface RootComponent: Deps1, Deps2
936+
""".trimIndent())
937+
938+
compileRunAndValidate()
939+
}
917940
}
918941

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
2+
Name: test/Yatagan$RootComponent.java
3+
package test;
4+
5+
import com.yandex.yatagan.AutoBuilder;
6+
import com.yandex.yatagan.internal.Checks;
7+
import com.yandex.yatagan.internal.YataganGenerated;
8+
import java.lang.Class;
9+
import java.lang.Override;
10+
import java.lang.SuppressWarnings;
11+
import java.util.Collections;
12+
import javax.annotation.processing.Generated;
13+
14+
@SuppressWarnings({"unchecked", "rawtypes", "NullableProblems"})
15+
@YataganGenerated
16+
@Generated("com.yandex.yatagan.codegen.impl.ComponentGenerator")
17+
public final class Yatagan$RootComponent implements RootComponent {
18+
private Yatagan$RootComponent() {
19+
}
20+
21+
@Override
22+
public TestClass getTestClass() {
23+
return new TestClass();
24+
}
25+
26+
public static AutoBuilder<Yatagan$RootComponent> autoBuilder() {
27+
return new AutoBuilderImpl();
28+
}
29+
30+
private static final class AutoBuilderImpl implements AutoBuilder<Yatagan$RootComponent> {
31+
@Override
32+
public final <I> AutoBuilder<Yatagan$RootComponent> provideInput(I input, Class<I> inputClass) {
33+
Checks.reportUnexpectedAutoBuilderInput(input.getClass(), Collections.emptyList());
34+
return this;
35+
}
36+
37+
@Override
38+
public final Yatagan$RootComponent create() {
39+
return new Yatagan$RootComponent();
40+
}
41+
}
42+
}
43+
44+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

0 commit comments

Comments
 (0)