From d5fd160fd3d4d6e250c0488dff3d9fd8428bf330 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 17 Jan 2019 19:12:18 +0100 Subject: [PATCH] JS: minor, do not use '==' on descriptors from built-ins Use KotlinBuiltIns.isString instead of equality with KotlinBuiltIns.string, which is more portable across different module configurations. Also use isSubtypeOf instead of DescriptorUtils.isSubclass and thus get rid of an extra error on an unresolved class in nativeAnnotationCheckers.kt --- .../native/nativeSetter/onToplevelExtensionFun.kt | 4 ++-- .../kotlin/js/resolve/nativeAnnotationCheckers.kt | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.kt b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.kt index 6352c917d21..7b34c5b72c3 100644 --- a/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.kt +++ b/compiler/testData/diagnostics/testsWithJsStdLib/native/nativeSetter/onToplevelExtensionFun.kt @@ -22,10 +22,10 @@ fun Int.set6(a: Double, v: String): Number fun Any.foo(a: String = "0.0", v: String = "str") = "OK" @nativeSetter -fun Int.set(a: A): Int? = 1 +fun Int.set(a: A): Int? = 1 @nativeSetter fun Int.set2(): String? = "OK" @nativeSetter -fun Int.set3(a: Any, b: Int, c: Any?) {} \ No newline at end of file +fun Int.set3(a: Any, b: Int, c: Any?) {} diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/nativeAnnotationCheckers.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/nativeAnnotationCheckers.kt index aad1c154253..ab6704ca204 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/nativeAnnotationCheckers.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/nativeAnnotationCheckers.kt @@ -27,8 +27,8 @@ import org.jetbrains.kotlin.js.translate.utils.AnnotationsUtils import org.jetbrains.kotlin.psi.KtDeclaration import org.jetbrains.kotlin.psi.KtNamedFunction import org.jetbrains.kotlin.resolve.DescriptorUtils -import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext import org.jetbrains.kotlin.resolve.checkers.DeclarationChecker +import org.jetbrains.kotlin.resolve.checkers.DeclarationCheckerContext import org.jetbrains.kotlin.resolve.descriptorUtil.builtIns import org.jetbrains.kotlin.types.TypeUtils import org.jetbrains.kotlin.types.typeUtil.isSubtypeOf @@ -68,12 +68,12 @@ internal abstract class AbstractNativeIndexerChecker( override fun additionalCheck(declaration: KtNamedFunction, descriptor: FunctionDescriptor, diagnosticHolder: DiagnosticSink) { val parameters = descriptor.valueParameters val builtIns = descriptor.builtIns - if (parameters.size > 0) { - val firstParamClassDescriptor = DescriptorUtils.getClassDescriptorForType(parameters.get(0).type) - if (firstParamClassDescriptor != builtIns.string && - !DescriptorUtils.isSubclass(firstParamClassDescriptor, builtIns.number) - ) { - diagnosticHolder.report(ErrorsJs.NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER.on(declaration.valueParameters.first(), indexerKind)) + if (parameters.isNotEmpty()) { + val firstParamType = parameters.first().type + if (!KotlinBuiltIns.isString(firstParamType) && !firstParamType.isSubtypeOf(builtIns.number.defaultType)) { + diagnosticHolder.report( + ErrorsJs.NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER.on(declaration.valueParameters.first(), indexerKind) + ) } }