From 6fb40878c4bbfdda1f9c61a0c3c5300527397269 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Fri, 8 May 2020 20:52:13 +0200 Subject: [PATCH] Minor, do not report "no reflection" error on KTypeParameter Since an implementation of KTypeParameter for stdlib is coming, an instance of which can be obtained through `typeOf`. --- .../checkers/AbstractReflectionApiCallChecker.kt | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/AbstractReflectionApiCallChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/AbstractReflectionApiCallChecker.kt index 0618532515d..7d978be0e29 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/AbstractReflectionApiCallChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/AbstractReflectionApiCallChecker.kt @@ -31,10 +31,13 @@ import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.storage.getValue import org.jetbrains.kotlin.util.OperatorNameConventions -private val ANY_MEMBER_NAMES = setOf("equals", "hashCode", "toString") +private val ALLOWED_MEMBER_NAMES = setOf( + "equals", "hashCode", "toString", "invoke", "name" +) private val ALLOWED_CLASSES = setOf( FqName("kotlin.reflect.KType"), + FqName("kotlin.reflect.KTypeParameter"), FqName("kotlin.reflect.KTypeProjection"), FqName("kotlin.reflect.KTypeProjection.Companion"), FqName("kotlin.reflect.KVariance") @@ -76,10 +79,8 @@ abstract class AbstractReflectionApiCallChecker( protected open fun isAllowedReflectionApi(descriptor: CallableDescriptor, containingClass: ClassDescriptor): Boolean { val name = descriptor.name - return name.asString() in ANY_MEMBER_NAMES || - name == OperatorNameConventions.INVOKE || - name.asString() == "name" || - DescriptorUtils.isSubclass(containingClass, kClass) && isAllowedKClassMember(descriptor.name) || + return name.asString() in ALLOWED_MEMBER_NAMES || + DescriptorUtils.isSubclass(containingClass, kClass) && isAllowedKClassMember(name) || (name.asString() == "get" || name.asString() == "set") && containingClass.isKPropertyClass() || containingClass.fqNameSafe in ALLOWED_CLASSES }