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
This commit is contained in:
Alexander Udalov
2019-01-17 19:12:18 +01:00
parent 31670622c0
commit d5fd160fd3
2 changed files with 9 additions and 9 deletions
@@ -22,10 +22,10 @@ fun Int.set6(a: Double, v: String): <!NATIVE_SETTER_WRONG_RETURN_TYPE!>Number<!>
fun Any.foo(<!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>a: String = "0.0"<!>, <!NATIVE_INDEXER_CAN_NOT_HAVE_DEFAULT_ARGUMENTS!>v: String = "str"<!>) = "OK"
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun Int.set(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: <!UNRESOLVED_REFERENCE!>A<!><!>): Int?<!> = 1
fun Int.set(a: <!UNRESOLVED_REFERENCE!>A<!>): Int?<!> = 1
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun Int.set2(): String?<!> = "OK"
<!NATIVE_INDEXER_WRONG_PARAMETER_COUNT!>@nativeSetter
fun Int.set3(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: Any<!>, b: Int, c: Any?)<!> {}
fun Int.set3(<!NATIVE_INDEXER_KEY_SHOULD_BE_STRING_OR_NUMBER!>a: Any<!>, b: Int, c: Any?)<!> {}
@@ -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)
)
}
}