diff --git a/idea/src/org/jetbrains/kotlin/idea/inspections/ReflectionNotFoundInspection.kt b/idea/src/org/jetbrains/kotlin/idea/inspections/ReflectionNotFoundInspection.kt index 5b4f12681f3..f7429376b1a 100644 --- a/idea/src/org/jetbrains/kotlin/idea/inspections/ReflectionNotFoundInspection.kt +++ b/idea/src/org/jetbrains/kotlin/idea/inspections/ReflectionNotFoundInspection.kt @@ -45,6 +45,8 @@ import org.jetbrains.kotlin.psi.JetVisitorVoid import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.serialization.deserialization.findClassAcrossModuleDependencies import org.jetbrains.kotlin.builtins.ReflectionTypes +import org.jetbrains.kotlin.psi.JetAnnotationEntry +import org.jetbrains.kotlin.psi.psiUtil.getStrictParentOfType import org.jetbrains.kotlin.utils.PathUtil import org.jetbrains.kotlin.utils.addToStdlib.firstIsInstanceOrNull import org.jetbrains.kotlin.utils.singletonOrEmptyList @@ -75,6 +77,8 @@ public class ReflectionNotFoundInspection : AbstractKotlinInspection() { val expectedType = expression.analyze().get(BindingContext.EXPECTED_EXPRESSION_TYPE, expression) if (expectedType != null && !ReflectionTypes.isReflectionType(expectedType)) return + if (expression.getStrictParentOfType() != null) return + // If a callable reference is used where a KFunction/KProperty/... expected, we should report that usage as dangerous // because reflection features will fail without kotlin-reflect.jar in the classpath. // If it's only used as a Function however (for example, "list.map(::function)"), we should not report anything diff --git a/idea/testData/inspections/reflectionNotFound/inspectionData/expected.xml b/idea/testData/inspections/reflectionNotFound/inspectionData/expected.xml index 51426e80ffa..fed4c656629 100644 --- a/idea/testData/inspections/reflectionNotFound/inspectionData/expected.xml +++ b/idea/testData/inspections/reflectionNotFound/inspectionData/expected.xml @@ -15,4 +15,12 @@ Reflection not found Reflection not found in the classpath + + withinAnnotationEntry.kt + 13 + light_idea_test_case + + Reflection not found + Reflection not found in the classpath + diff --git a/idea/testData/inspections/reflectionNotFound/withinAnnotationEntry.kt b/idea/testData/inspections/reflectionNotFound/withinAnnotationEntry.kt new file mode 100644 index 00000000000..3e75d6bc3e8 --- /dev/null +++ b/idea/testData/inspections/reflectionNotFound/withinAnnotationEntry.kt @@ -0,0 +1,15 @@ +package test + +// WITH_RUNTIME + +import kotlin.reflect.KClass + +annotation class A(val arg: KClass<*>, val args: Array>, vararg val other: KClass<*>) + +A(Int::class, array(String::class), Double::class, Char::class) +class MyClass { + throws(Exception::class) + fun foo() { + Exception::class + } +}