From e28b4dfbc77b274dcc9396b9df47ef9aa088d7f5 Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Sat, 21 Jan 2017 13:41:11 +0900 Subject: [PATCH] Kapt3: Do not check type for star projection, it causes the infinite recursion. Also limit recursion depth to 10. (KT-15841) --- .../kotlin/kapt3/stubs/errorTypeConversion.kt | 9 ++++-- .../nonExistentClassTypesConversion.kt | 9 +++++- .../nonExistentClassTypesConversion.txt | 30 +++++++++++++++++++ 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/errorTypeConversion.kt b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/errorTypeConversion.kt index e605e69de0b..373a13350ea 100644 --- a/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/errorTypeConversion.kt +++ b/plugins/kapt3/src/org/jetbrains/kotlin/kapt3/stubs/errorTypeConversion.kt @@ -107,8 +107,13 @@ private fun convertFunctionType(type: KtFunctionType, converter: ClassFileToSour return treeMaker.TypeApply(treeMaker.SimpleName("Function" + (parameterTypes.size - 1)), parameterTypes) } -fun KotlinType.containsErrorTypes(): Boolean { +fun KotlinType.containsErrorTypes(allowedDepth: Int = 10): Boolean { + // Need to limit recursion depth in case of complex recursive generics + if (allowedDepth <= 0) { + return false + } + if (this.isError) return true - if (this.arguments.any { it.type.containsErrorTypes() }) return true + if (this.arguments.any { !it.isStarProjection && it.type.containsErrorTypes(allowedDepth - 1) }) return true return false } \ No newline at end of file diff --git a/plugins/kapt3/testData/converter/nonExistentClassTypesConversion.kt b/plugins/kapt3/testData/converter/nonExistentClassTypesConversion.kt index dba98b62b68..c2ac8f30d60 100644 --- a/plugins/kapt3/testData/converter/nonExistentClassTypesConversion.kt +++ b/plugins/kapt3/testData/converter/nonExistentClassTypesConversion.kt @@ -20,6 +20,9 @@ class Test { val m = ABC() val n = "".toString() + lateinit var o11: List>>>>>>>>> + lateinit var o10: List>>>>>>>> + fun f1(a: ABC): BCD? { return null } @@ -31,4 +34,8 @@ class Test { } fun f4() = ABC() -} \ No newline at end of file + + fun MyType.f5(): java.lang.Class>? = null +} + +class MyType \ No newline at end of file diff --git a/plugins/kapt3/testData/converter/nonExistentClassTypesConversion.txt b/plugins/kapt3/testData/converter/nonExistentClassTypesConversion.txt index 14d7ed140a3..f4835116d5e 100644 --- a/plugins/kapt3/testData/converter/nonExistentClassTypesConversion.txt +++ b/plugins/kapt3/testData/converter/nonExistentClassTypesConversion.txt @@ -1,3 +1,13 @@ +public final class MyType { + + public MyType() { + super(); + } +} + +//////////////////// + + @kotlin.Suppress(names = {"UNRESOLVED_REFERENCE"}) public final class Test { public ABC a; @@ -14,6 +24,8 @@ public final class Test { public ABC.BCD.EFG l; private final error.NonExistentClass m = null; private final java.lang.String n = ""; + public java.util.List>>>>>>>>> o11; + public List>>>>>>>> o10; public final ABC getA() { return null; @@ -98,6 +110,20 @@ public final class Test { return null; } + public final java.util.List>>>>>>>>> getO11() { + return null; + } + + public final void setO11(java.util.List>>>>>>>>> p0) { + } + + public final List>>>>>>>> getO10() { + return null; + } + + public final void setO10(List>>>>>>>> p0) { + } + public final BCD f1(ABC a) { return null; } @@ -113,6 +139,10 @@ public final class Test { return null; } + public final java.lang.Class> f5(MyType $receiver) { + return null; + } + public Test() { super(); }