JVM: KT-40665 more exact check for intrinsified range 'contains'

This commit is contained in:
Dmitry Petrov
2020-07-29 11:38:32 +03:00
parent 0559e192ee
commit f2493d0950
10 changed files with 61 additions and 5 deletions
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.codegen.range.inExpression.InExpressionGenerator
import org.jetbrains.kotlin.codegen.range.inExpression.InFloatingPointRangeLiteralExpressionGenerator
import org.jetbrains.kotlin.codegen.range.inExpression.InIntegralContinuousRangeExpressionGenerator
import org.jetbrains.kotlin.descriptors.CallableDescriptor
import org.jetbrains.kotlin.descriptors.isTopLevelInPackage
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtForExpression
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
@@ -208,17 +208,25 @@ fun isPrimitiveRangeContains(descriptor: CallableDescriptor): Boolean {
}
fun isUnsignedIntegerRangeContains(descriptor: CallableDescriptor): Boolean {
if (descriptor.name.asString() != "contains") return false
val dispatchReceiverType = descriptor.dispatchReceiverParameter?.type
val extensionReceiverType = descriptor.extensionReceiverParameter?.type
return (dispatchReceiverType != null && isUnsignedRange(dispatchReceiverType)) ||
(extensionReceiverType != null && isUnsignedRange(extensionReceiverType))
when {
dispatchReceiverType != null && extensionReceiverType == null -> {
if (descriptor.name.asString() != "contains") return false
return isUnsignedRange(dispatchReceiverType)
}
extensionReceiverType != null && dispatchReceiverType == null -> {
if (!descriptor.isTopLevelInPackage("contains", "kotlin.ranges")) return false
return isUnsignedRange(extensionReceiverType)
}
else ->
return false
}
}
fun isPrimitiveNumberRangeExtensionContainsPrimitiveNumber(descriptor: CallableDescriptor): Boolean {
if (descriptor.name.asString() != "contains") return false
if (!descriptor.isTopLevelInPackage("contains", "kotlin.ranges")) return false
val extensionReceiverType = descriptor.extensionReceiverParameter?.type ?: return false