From 0a0de8da29c98992337a114a982f94820a06b41f Mon Sep 17 00:00:00 2001 From: Yan Zhulanow Date: Thu, 16 Nov 2017 15:22:47 +0900 Subject: [PATCH] Kapt: Fix correctErrorTypes for getters of properties defined in the primary constructor --- .../stubs/ClassFileToSourceStubConverter.kt | 3 +- .../kapt3/test/AbstractKotlinKapt3Test.kt | 4 ++- .../converter/errorLocationMapping.kt | 30 ++++++++++--------- .../converter/errorLocationMapping.txt | 4 +-- 4 files changed, 23 insertions(+), 18 deletions(-) diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt index 167a0004a18..395daecd38b 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -612,7 +612,8 @@ class ClassFileToSourceStubConverter( val element = kaptContext.origins[method]?.element when (element) { is KtFunction -> element.typeReference - is KtProperty -> if (method.name.startsWith("get")) element.typeReference else null + is KtProperty -> if (descriptor is PropertyGetterDescriptor) element.typeReference else null + is KtParameter -> if (descriptor is PropertyGetterDescriptor) element.typeReference else null else -> null } }, diff --git a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/AbstractKotlinKapt3Test.kt b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/AbstractKotlinKapt3Test.kt index 1c19c017762..6edce52938a 100644 --- a/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/AbstractKotlinKapt3Test.kt +++ b/plugins/kapt3/kapt3-compiler/test/org/jetbrains/kotlin/kapt3/test/AbstractKotlinKapt3Test.kt @@ -218,10 +218,12 @@ open class AbstractClassFileToSourceStubConverterTest : AbstractKotlinKapt3Test( log.flush() + val lineSeparator = System.getProperty("line.separator") + System.err.println(actualErrors.joinToString(lineSeparator)) + if (expectedErrors.isEmpty()) { error("There were errors during analysis. See errors above. Stubs:\n\n$actual") } else { - val lineSeparator = System.getProperty("line.separator") TestCase.assertEquals("Expected error matching failed", expectedErrors.joinToString(lineSeparator), actualErrors.joinToString(lineSeparator)) diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt b/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt index e691f65c10d..b5937a8e89c 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.kt @@ -1,19 +1,21 @@ // CORRECT_ERROR_TYPES -// EXPECTED_ERROR(10;12) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (31, 5)) -// EXPECTED_ERROR(10;19) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (24, 50)) -// EXPECTED_ERROR(12;12) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (32, 5)) -// EXPECTED_ERROR(12;34) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (24, 62)) -// EXPECTED_ERROR(27;18) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (31, 5)) -// EXPECTED_ERROR(33;5) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (31, 5)) -// EXPECTED_ERROR(35;5) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (24, 34)) -// EXPECTED_ERROR(36;30) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (24, 34)) -// EXPECTED_ERROR(38;18) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (32, 5)) -// EXPECTED_ERROR(44;5) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (32, 5)) -// EXPECTED_ERROR(54;5) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (35, 5)) -// EXPECTED_ERROR(5;11) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (21, 1)) -// EXPECTED_ERROR(60;5) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (37, 5)) -// EXPECTED_ERROR(73;18) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (40, 5)) +// EXPECTED_ERROR(10;12) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (33, 5)) +// EXPECTED_ERROR(10;19) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (26, 50)) +// EXPECTED_ERROR(12;12) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (34, 5)) +// EXPECTED_ERROR(12;34) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (26, 62)) +// EXPECTED_ERROR(22;18) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (26, 50)) +// EXPECTED_ERROR(27;18) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (33, 5)) +// EXPECTED_ERROR(28;33) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (26, 62)) +// EXPECTED_ERROR(33;5) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (33, 5)) +// EXPECTED_ERROR(35;5) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (26, 34)) +// EXPECTED_ERROR(36;30) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (26, 34)) +// EXPECTED_ERROR(38;18) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (34, 5)) +// EXPECTED_ERROR(44;5) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (34, 5)) +// EXPECTED_ERROR(54;5) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (37, 5)) +// EXPECTED_ERROR(5;11) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (23, 1)) +// EXPECTED_ERROR(60;5) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (39, 5)) +// EXPECTED_ERROR(73;18) cannot find symbol (Kotlin location: /errorLocationMapping.kt: (42, 5)) @file:Suppress("UNRESOLVED_REFERENCE", "ANNOTATION_PARAMETER_MUST_BE_CONST", "NON_CONST_VAL_USED_IN_CONSTANT_EXPRESSION") import kotlin.reflect.KClass diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.txt b/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.txt index c0fa0ca5ceb..8ff5d0db450 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/errorLocationMapping.txt @@ -48,13 +48,13 @@ public final class ErrorInConstructorParameter { @org.jetbrains.annotations.NotNull() @kapt.internal.KaptSignature(value = "getB()Lerror/NonExistentClass;") - public final error.NonExistentClass getB() { + public final ABC getB() { return null; } @org.jetbrains.annotations.NotNull() @kapt.internal.KaptSignature(value = "getC()Ljava/util/List;") - public final java.util.List getC() { + public final java.util.List getC() { return null; }