Skip to content

Commit e28b4df

Browse files
committed
Kapt3: Do not check type for star projection, it causes the infinite recursion. Also limit recursion depth to 10. (KT-15841)
1 parent 48a66c9 commit e28b4df

File tree

3 files changed

+45
-3
lines changed

3 files changed

+45
-3
lines changed

plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/errorTypeConversion.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,13 @@ private fun convertFunctionType(type: KtFunctionType, converter: ClassFileToSour
107107
return treeMaker.TypeApply(treeMaker.SimpleName("Function" + (parameterTypes.size - 1)), parameterTypes)
108108
}
109109

110-
fun KotlinType.containsErrorTypes(): Boolean {
110+
fun KotlinType.containsErrorTypes(allowedDepth: Int = 10): Boolean {
111+
// Need to limit recursion depth in case of complex recursive generics
112+
if (allowedDepth <= 0) {
113+
return false
114+
}
115+
111116
if (this.isError) return true
112-
if (this.arguments.any { it.type.containsErrorTypes() }) return true
117+
if (this.arguments.any { !it.isStarProjection && it.type.containsErrorTypes(allowedDepth - 1) }) return true
113118
return false
114119
}

plugins/kapt3/testData/converter/nonExistentClassTypesConversion.kt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class Test {
2020
val m = ABC()
2121
val n = "".toString()
2222

23+
lateinit var o11: List<List<List<List<List<List<List<List<List<List<ABC>>>>>>>>>>
24+
lateinit var o10: List<List<List<List<List<List<List<List<List<ABC>>>>>>>>>
25+
2326
fun f1(a: ABC): BCD? {
2427
return null
2528
}
@@ -31,4 +34,8 @@ class Test {
3134
}
3235

3336
fun f4() = ABC()
34-
}
37+
38+
fun <T> MyType<T>.f5(): java.lang.Class<Enum<*>>? = null
39+
}
40+
41+
class MyType<T>

plugins/kapt3/testData/converter/nonExistentClassTypesConversion.txt

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
public final class MyType<T extends java.lang.Object> {
2+
3+
public MyType() {
4+
super();
5+
}
6+
}
7+
8+
////////////////////
9+
10+
111
@kotlin.Suppress(names = {"UNRESOLVED_REFERENCE"})
212
public final class Test {
313
public ABC a;
@@ -14,6 +24,8 @@ public final class Test {
1424
public ABC.BCD.EFG l;
1525
private final error.NonExistentClass m = null;
1626
private final java.lang.String n = "";
27+
public java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends error.NonExistentClass>>>>>>>>>> o11;
28+
public List<List<List<List<List<List<List<List<List<ABC>>>>>>>>> o10;
1729

1830
public final ABC getA() {
1931
return null;
@@ -98,6 +110,20 @@ public final class Test {
98110
return null;
99111
}
100112

113+
public final java.util.List<java.util.List<java.util.List<java.util.List<java.util.List<java.util.List<java.util.List<java.util.List<java.util.List<java.util.List<error.NonExistentClass>>>>>>>>>> getO11() {
114+
return null;
115+
}
116+
117+
public final void setO11(java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends java.util.List<? extends error.NonExistentClass>>>>>>>>>> p0) {
118+
}
119+
120+
public final List<List<List<List<List<List<List<List<List<ABC>>>>>>>>> getO10() {
121+
return null;
122+
}
123+
124+
public final void setO10(List<List<List<List<List<List<List<List<List<ABC>>>>>>>>> p0) {
125+
}
126+
101127
public final BCD f1(ABC a) {
102128
return null;
103129
}
@@ -113,6 +139,10 @@ public final class Test {
113139
return null;
114140
}
115141

142+
public final <T extends java.lang.Object>java.lang.Class<java.lang.Enum<?>> f5(MyType<T> $receiver) {
143+
return null;
144+
}
145+
116146
public Test() {
117147
super();
118148
}

0 commit comments

Comments
 (0)