From e87bccd5c7a1ebb42fc957fb2e9396757b3e526d Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Tue, 8 Aug 2023 12:50:25 +0200 Subject: [PATCH] K2: fix reporting of NO_REFLECTION_IN_CLASS_PATH on implicit invoke #KT-61054 Fixed --- .../checkers/expression/AbstractFirReflectionApiCallChecker.kt | 2 +- .../testsWithStdLib/reflection/noReflectionInClassPath.kt | 1 + .../testsWithStdLib/reflection/noReflectionInClassPath.txt | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/AbstractFirReflectionApiCallChecker.kt b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/AbstractFirReflectionApiCallChecker.kt index 16ad0a225ef..725e0066ebe 100644 --- a/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/AbstractFirReflectionApiCallChecker.kt +++ b/compiler/fir/checkers/src/org/jetbrains/kotlin/fir/analysis/checkers/expression/AbstractFirReflectionApiCallChecker.kt @@ -46,7 +46,7 @@ abstract class AbstractFirReflectionApiCallChecker : FirBasicExpressionChecker() if (containingClassId == null || containingClassId.packageFqName != StandardNames.KOTLIN_REFLECT_FQ_NAME) return if (!isAllowedReflectionApi(referencedSymbol.name, containingClassId, context)) { - report(resolvedReference.source, context, reporter) + report(resolvedReference.source ?: expression.source, context, reporter) } } diff --git a/compiler/testData/diagnostics/testsWithStdLib/reflection/noReflectionInClassPath.kt b/compiler/testData/diagnostics/testsWithStdLib/reflection/noReflectionInClassPath.kt index d990500e468..66ba4ddaf2f 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/reflection/noReflectionInClassPath.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/reflection/noReflectionInClassPath.kt @@ -21,6 +21,7 @@ fun y01() = Foo::prop.getter fun y02() = Foo::class.members fun y03() = Foo::class.simpleName fun y04() = Foo::class.properties +fun y05() = Foo::prop.getter(Foo(42)) fun kclass(k: KClass<*>, kt: KClass) { k.simpleName diff --git a/compiler/testData/diagnostics/testsWithStdLib/reflection/noReflectionInClassPath.txt b/compiler/testData/diagnostics/testsWithStdLib/reflection/noReflectionInClassPath.txt index d8b8f45bd45..2d7e50efb0e 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/reflection/noReflectionInClassPath.txt +++ b/compiler/testData/diagnostics/testsWithStdLib/reflection/noReflectionInClassPath.txt @@ -16,6 +16,7 @@ public fun y01(): kotlin.reflect.KProperty1.Getter public fun y02(): kotlin.collections.Collection> public fun y03(): kotlin.String? public fun y04(): [Error type: Return type for function cannot be resolved] +public fun y05(): kotlin.Any public final class Foo { public constructor Foo(/*0*/ prop: kotlin.Any) @@ -25,3 +26,4 @@ public final class Foo { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String } +