Support unsigned integers in intrinsic range values
This commit is contained in:
@@ -8,6 +8,7 @@ package org.jetbrains.kotlin.codegen.range
|
|||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.RANGES_PACKAGE_FQ_NAME
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns.RANGES_PACKAGE_FQ_NAME
|
||||||
import org.jetbrains.kotlin.builtins.PrimitiveType
|
import org.jetbrains.kotlin.builtins.PrimitiveType
|
||||||
|
import org.jetbrains.kotlin.builtins.UnsignedTypes
|
||||||
import org.jetbrains.kotlin.codegen.AsmUtil.isPrimitiveNumberClassDescriptor
|
import org.jetbrains.kotlin.codegen.AsmUtil.isPrimitiveNumberClassDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
import org.jetbrains.kotlin.diagnostics.PsiDiagnosticUtils
|
import org.jetbrains.kotlin.diagnostics.PsiDiagnosticUtils
|
||||||
@@ -74,31 +75,30 @@ private const val CLOSED_FLOATING_POINT_RANGE_FQN = "kotlin.ranges.ClosedFloatin
|
|||||||
private const val COMPARABLE_RANGE_FQN = "kotlin.ranges.ComparableRange"
|
private const val COMPARABLE_RANGE_FQN = "kotlin.ranges.ComparableRange"
|
||||||
private const val UINT_RANGE_FQN = "kotlin.ranges.UIntRange"
|
private const val UINT_RANGE_FQN = "kotlin.ranges.UIntRange"
|
||||||
private const val ULONG_RANGE_FQN = "kotlin.ranges.ULongRange"
|
private const val ULONG_RANGE_FQN = "kotlin.ranges.ULongRange"
|
||||||
|
private const val UINT_PROGRESSION_FQN = "kotlin.ranges.UIntProgression"
|
||||||
|
private const val ULONG_PROGRESSION_FQN = "kotlin.ranges.ULongProgression"
|
||||||
|
|
||||||
fun getRangeOrProgressionElementType(rangeType: KotlinType): KotlinType? {
|
fun getRangeOrProgressionElementType(rangeType: KotlinType): KotlinType? {
|
||||||
val rangeClassDescriptor = rangeType.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
val rangeClassDescriptor = rangeType.constructor.declarationDescriptor as? ClassDescriptor ?: return null
|
||||||
val builtIns = rangeClassDescriptor.builtIns
|
val builtIns = rangeClassDescriptor.builtIns
|
||||||
|
|
||||||
return when (rangeClassDescriptor.fqNameSafe.asString()) {
|
return when (rangeClassDescriptor.fqNameSafe.asString()) {
|
||||||
CHAR_RANGE_FQN -> builtIns.charType
|
CHAR_RANGE_FQN, CHAR_PROGRESSION_FQN -> builtIns.charType
|
||||||
INT_RANGE_FQN -> builtIns.intType
|
INT_RANGE_FQN, INT_PROGRESSION_FQN -> builtIns.intType
|
||||||
LONG_RANGE_FQN -> builtIns.longType
|
LONG_RANGE_FQN, LONG_PROGRESSION_FQN -> builtIns.longType
|
||||||
|
|
||||||
CHAR_PROGRESSION_FQN -> builtIns.charType
|
|
||||||
INT_PROGRESSION_FQN -> builtIns.intType
|
|
||||||
LONG_PROGRESSION_FQN -> builtIns.longType
|
|
||||||
|
|
||||||
CLOSED_FLOAT_RANGE_FQN -> builtIns.floatType
|
CLOSED_FLOAT_RANGE_FQN -> builtIns.floatType
|
||||||
CLOSED_DOUBLE_RANGE_FQN -> builtIns.doubleType
|
CLOSED_DOUBLE_RANGE_FQN -> builtIns.doubleType
|
||||||
|
|
||||||
CLOSED_RANGE_FQN -> rangeType.arguments.singleOrNull()?.type
|
CLOSED_RANGE_FQN -> rangeType.arguments.singleOrNull()?.type
|
||||||
|
|
||||||
CLOSED_FLOATING_POINT_RANGE_FQN -> rangeType.arguments.singleOrNull()?.type
|
CLOSED_FLOATING_POINT_RANGE_FQN -> rangeType.arguments.singleOrNull()?.type
|
||||||
|
|
||||||
COMPARABLE_RANGE_FQN -> rangeType.arguments.singleOrNull()?.type
|
COMPARABLE_RANGE_FQN -> rangeType.arguments.singleOrNull()?.type
|
||||||
|
|
||||||
UINT_RANGE_FQN -> rangeClassDescriptor.findTypeInModuleByTopLevelClassFqName(KotlinBuiltIns.FQ_NAMES.uIntFqName)
|
UINT_RANGE_FQN, UINT_PROGRESSION_FQN ->
|
||||||
ULONG_RANGE_FQN -> rangeClassDescriptor.findTypeInModuleByTopLevelClassFqName(KotlinBuiltIns.FQ_NAMES.uLongFqName)
|
rangeClassDescriptor.findTypeInModuleByTopLevelClassFqName(KotlinBuiltIns.FQ_NAMES.uIntFqName)
|
||||||
|
|
||||||
|
ULONG_RANGE_FQN, ULONG_PROGRESSION_FQN ->
|
||||||
|
rangeClassDescriptor.findTypeInModuleByTopLevelClassFqName(KotlinBuiltIns.FQ_NAMES.uLongFqName)
|
||||||
|
|
||||||
else -> null
|
else -> null
|
||||||
}
|
}
|
||||||
@@ -125,12 +125,10 @@ fun isPrimitiveNumberRangeTo(rangeTo: CallableDescriptor) =
|
|||||||
isPrimitiveRangeToExtension(rangeTo)
|
isPrimitiveRangeToExtension(rangeTo)
|
||||||
|
|
||||||
fun isUnsignedIntegerRangeTo(rangeTo: CallableDescriptor) =
|
fun isUnsignedIntegerRangeTo(rangeTo: CallableDescriptor) =
|
||||||
"rangeTo" == rangeTo.name.asString() && isUnsignedIntegerClass(rangeTo.containingDeclaration)
|
"rangeTo" == rangeTo.name.asString() && isUnsignedIntegerClassDescriptor(rangeTo.containingDeclaration)
|
||||||
|
|
||||||
fun isUnsignedIntegerClass(descriptor: DeclarationDescriptor) =
|
fun isUnsignedIntegerClassDescriptor(descriptor: DeclarationDescriptor?) =
|
||||||
descriptor is ClassDescriptor && descriptor.defaultType.let { type ->
|
descriptor != null && UnsignedTypes.isUnsignedClass(descriptor)
|
||||||
KotlinBuiltIns.isUByte(type) || KotlinBuiltIns.isUShort(type) || KotlinBuiltIns.isUInt(type) || KotlinBuiltIns.isULong(type)
|
|
||||||
}
|
|
||||||
|
|
||||||
private inline fun CallableDescriptor.isTopLevelExtensionOnType(
|
private inline fun CallableDescriptor.isTopLevelExtensionOnType(
|
||||||
name: String,
|
name: String,
|
||||||
@@ -152,11 +150,21 @@ fun isPrimitiveNumberDownTo(descriptor: CallableDescriptor) =
|
|||||||
isPrimitiveNumberClassDescriptor(it.constructor.declarationDescriptor)
|
isPrimitiveNumberClassDescriptor(it.constructor.declarationDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isUnsignedIntegerDownTo(descriptor: CallableDescriptor) =
|
||||||
|
descriptor.isTopLevelExtensionOnType("downTo", "kotlin.ranges") {
|
||||||
|
isUnsignedIntegerClassDescriptor(it.constructor.declarationDescriptor)
|
||||||
|
}
|
||||||
|
|
||||||
fun isPrimitiveNumberUntil(descriptor: CallableDescriptor) =
|
fun isPrimitiveNumberUntil(descriptor: CallableDescriptor) =
|
||||||
descriptor.isTopLevelExtensionOnType("until", "kotlin.ranges") {
|
descriptor.isTopLevelExtensionOnType("until", "kotlin.ranges") {
|
||||||
isPrimitiveNumberClassDescriptor(it.constructor.declarationDescriptor)
|
isPrimitiveNumberClassDescriptor(it.constructor.declarationDescriptor)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun isUnsignedIntegerUntil(descriptor: CallableDescriptor) =
|
||||||
|
descriptor.isTopLevelExtensionOnType("until", "kotlin.ranges") {
|
||||||
|
isUnsignedIntegerClassDescriptor(it.constructor.declarationDescriptor)
|
||||||
|
}
|
||||||
|
|
||||||
fun isArrayOrPrimitiveArrayIndices(descriptor: CallableDescriptor) =
|
fun isArrayOrPrimitiveArrayIndices(descriptor: CallableDescriptor) =
|
||||||
descriptor.isTopLevelExtensionOnType("indices", "kotlin.collections") {
|
descriptor.isTopLevelExtensionOnType("indices", "kotlin.collections") {
|
||||||
KotlinBuiltIns.isArray(it) || KotlinBuiltIns.isPrimitiveArray(it)
|
KotlinBuiltIns.isArray(it) || KotlinBuiltIns.isPrimitiveArray(it)
|
||||||
|
|||||||
@@ -17,7 +17,7 @@
|
|||||||
package org.jetbrains.kotlin.codegen.range
|
package org.jetbrains.kotlin.codegen.range
|
||||||
|
|
||||||
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
import org.jetbrains.kotlin.builtins.KotlinBuiltIns
|
||||||
import org.jetbrains.kotlin.codegen.*
|
import org.jetbrains.kotlin.codegen.ExpressionCodegen
|
||||||
import org.jetbrains.kotlin.config.LanguageFeature
|
import org.jetbrains.kotlin.config.LanguageFeature
|
||||||
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
import org.jetbrains.kotlin.descriptors.CallableDescriptor
|
||||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||||
@@ -118,11 +118,11 @@ private fun ExpressionCodegen.createIntrinsifiedRangeValueOrNull(rangeCall: Reso
|
|||||||
val rangeCallee = rangeCall.resultingDescriptor
|
val rangeCallee = rangeCall.resultingDescriptor
|
||||||
|
|
||||||
return when {
|
return when {
|
||||||
isPrimitiveNumberRangeTo(rangeCallee) ->
|
isPrimitiveNumberRangeTo(rangeCallee) || isUnsignedIntegerRangeTo(rangeCallee) ->
|
||||||
PrimitiveNumberRangeLiteralRangeValue(rangeCall)
|
PrimitiveNumberRangeLiteralRangeValue(rangeCall)
|
||||||
isPrimitiveNumberDownTo(rangeCallee) ->
|
isPrimitiveNumberDownTo(rangeCallee) || isUnsignedIntegerDownTo(rangeCallee) ->
|
||||||
DownToProgressionRangeValue(rangeCall)
|
DownToProgressionRangeValue(rangeCall)
|
||||||
isPrimitiveNumberUntil(rangeCallee) ->
|
isPrimitiveNumberUntil(rangeCallee) || isUnsignedIntegerUntil(rangeCallee) ->
|
||||||
PrimitiveNumberUntilRangeValue(rangeCall)
|
PrimitiveNumberUntilRangeValue(rangeCall)
|
||||||
isArrayOrPrimitiveArrayIndices(rangeCallee) ->
|
isArrayOrPrimitiveArrayIndices(rangeCallee) ->
|
||||||
ArrayIndicesRangeValue(rangeCall)
|
ArrayIndicesRangeValue(rangeCall)
|
||||||
|
|||||||
+4
@@ -47,6 +47,10 @@ fun getComparisonGeneratorForKotlinType(kotlinType: KotlinType): ComparisonGener
|
|||||||
FloatComparisonGenerator
|
FloatComparisonGenerator
|
||||||
KotlinBuiltIns.isDouble(kotlinType) ->
|
KotlinBuiltIns.isDouble(kotlinType) ->
|
||||||
DoubleComparisonGenerator
|
DoubleComparisonGenerator
|
||||||
|
KotlinBuiltIns.isUInt(kotlinType) ->
|
||||||
|
UIntComparisonGenerator
|
||||||
|
KotlinBuiltIns.isULong(kotlinType) ->
|
||||||
|
ULongComparisonGenerator
|
||||||
else ->
|
else ->
|
||||||
throw UnsupportedOperationException("Unexpected element type: $kotlinType")
|
throw UnsupportedOperationException("Unexpected element type: $kotlinType")
|
||||||
}
|
}
|
||||||
|
|||||||
+43
@@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright 2010-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license
|
||||||
|
* that can be found in the license/LICENSE.txt file.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.jetbrains.kotlin.codegen.range.comparison
|
||||||
|
|
||||||
|
import org.jetbrains.org.objectweb.asm.Label
|
||||||
|
import org.jetbrains.org.objectweb.asm.Opcodes
|
||||||
|
import org.jetbrains.org.objectweb.asm.Type
|
||||||
|
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter
|
||||||
|
|
||||||
|
class UnsignedIntegerComparisonGenerator(
|
||||||
|
override val comparedType: Type,
|
||||||
|
private val compareMethodName: String
|
||||||
|
) : ComparisonGenerator {
|
||||||
|
|
||||||
|
private val compareMethodDescriptor = Type.getMethodDescriptor(Type.INT_TYPE, comparedType, comparedType)
|
||||||
|
|
||||||
|
override fun jumpIfGreaterOrEqual(v: InstructionAdapter, label: Label) {
|
||||||
|
compareAndJump(v, label, Opcodes.IFGE)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpIfLessOrEqual(v: InstructionAdapter, label: Label) {
|
||||||
|
compareAndJump(v, label, Opcodes.IFLE)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpIfGreater(v: InstructionAdapter, label: Label) {
|
||||||
|
compareAndJump(v, label, Opcodes.IFGT)
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun jumpIfLess(v: InstructionAdapter, label: Label) {
|
||||||
|
compareAndJump(v, label, Opcodes.IFLT)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun compareAndJump(v: InstructionAdapter, label: Label, opcode: Int) {
|
||||||
|
v.invokestatic("kotlin/UnsignedKt", compareMethodName, compareMethodDescriptor, false)
|
||||||
|
v.visitJumpInsn(opcode, label)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val UIntComparisonGenerator = UnsignedIntegerComparisonGenerator(Type.INT_TYPE, "uintCompare")
|
||||||
|
val ULongComparisonGenerator = UnsignedIntegerComparisonGenerator(Type.LONG_TYPE, "ulongCompare")
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
const val MaxUI = UInt.MAX_VALUE
|
||||||
|
const val MinUI = UInt.MIN_VALUE
|
||||||
|
|
||||||
|
const val MaxUL = ULong.MAX_VALUE
|
||||||
|
const val MinUL = ULong.MIN_VALUE
|
||||||
|
|
||||||
|
val M = MaxUI.toULong()
|
||||||
|
|
||||||
|
fun testSimpleUIntLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 6u downTo 1u) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 654321) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testEmptyUIntLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 1u downTo 6u) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 0) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testSimpleULongLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 6UL downTo 1UL) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 654321) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testEmptyULongLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 1UL downTo 6UL) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 0) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testULongLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in M+6UL downTo M+1UL) {
|
||||||
|
s = s*10 + (i-M).toInt()
|
||||||
|
}
|
||||||
|
if (s != 654321) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testEmptyULongLoop2() {
|
||||||
|
var s = 0
|
||||||
|
for (i in M+1UL downTo M+6UL) {
|
||||||
|
s = s*10 + (i-M).toInt()
|
||||||
|
}
|
||||||
|
if (s != 0) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testMaxUIdownToMinUI() {
|
||||||
|
val xs = ArrayList<UInt>()
|
||||||
|
for (i in MinUI downTo MaxUI) {
|
||||||
|
xs.add(i)
|
||||||
|
if (xs.size > 23) break
|
||||||
|
}
|
||||||
|
if (xs.size > 0) {
|
||||||
|
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testMaxULdownToMinUL() {
|
||||||
|
val xs = ArrayList<ULong>()
|
||||||
|
for (i in MinUL downTo MaxUL) {
|
||||||
|
xs.add(i)
|
||||||
|
if (xs.size > 23) break
|
||||||
|
}
|
||||||
|
if (xs.size > 0) {
|
||||||
|
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testSimpleUIntLoop()
|
||||||
|
testEmptyUIntLoop()
|
||||||
|
testSimpleULongLoop()
|
||||||
|
testEmptyULongLoop()
|
||||||
|
testULongLoop()
|
||||||
|
testEmptyULongLoop2()
|
||||||
|
testMaxUIdownToMinUI()
|
||||||
|
testMaxULdownToMinUL()
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
const val MaxUI = UInt.MAX_VALUE
|
||||||
|
const val MinUI = UInt.MIN_VALUE
|
||||||
|
|
||||||
|
const val MaxUL = ULong.MAX_VALUE
|
||||||
|
const val MinUL = ULong.MIN_VALUE
|
||||||
|
|
||||||
|
val M = MaxUI.toULong()
|
||||||
|
|
||||||
|
fun testSimpleUIntLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 1u .. 6u) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 123456) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testEmptyUIntLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 6u .. 1u) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 0) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testSimpleULongLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 1UL .. 6UL) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 123456) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testEmptyULongLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 6UL .. 1UL) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 0) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testULongLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in M+1UL..M+6UL) {
|
||||||
|
s = s*10 + (i-M).toInt()
|
||||||
|
}
|
||||||
|
if (s != 123456) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testEmptyULongLoop2() {
|
||||||
|
var s = 0
|
||||||
|
for (i in M+6UL..M+1UL) {
|
||||||
|
s = s*10 + (i-M).toInt()
|
||||||
|
}
|
||||||
|
if (s != 0) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testMaxUItoMinUI() {
|
||||||
|
val xs = ArrayList<UInt>()
|
||||||
|
for (i in MaxUI..MinUI) {
|
||||||
|
xs.add(i)
|
||||||
|
if (xs.size > 23) break
|
||||||
|
}
|
||||||
|
if (xs.size > 0) {
|
||||||
|
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testMaxULtoMinUL() {
|
||||||
|
val xs = ArrayList<ULong>()
|
||||||
|
for (i in MaxUL..MinUL) {
|
||||||
|
xs.add(i)
|
||||||
|
if (xs.size > 23) break
|
||||||
|
}
|
||||||
|
if (xs.size > 0) {
|
||||||
|
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testSimpleUIntLoop()
|
||||||
|
testEmptyUIntLoop()
|
||||||
|
testSimpleULongLoop()
|
||||||
|
testEmptyULongLoop()
|
||||||
|
testULongLoop()
|
||||||
|
testEmptyULongLoop2()
|
||||||
|
testMaxUItoMinUI()
|
||||||
|
testMaxULtoMinUL()
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,93 @@
|
|||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
const val MaxUI = UInt.MAX_VALUE
|
||||||
|
const val MinUI = UInt.MIN_VALUE
|
||||||
|
|
||||||
|
const val MaxUL = ULong.MAX_VALUE
|
||||||
|
const val MinUL = ULong.MIN_VALUE
|
||||||
|
|
||||||
|
val M = MaxUI.toULong()
|
||||||
|
|
||||||
|
fun testSimpleUIntLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 1u until 6u) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 12345) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testEmptyUIntLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 6u until 1u) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 0) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testSimpleULongLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 1UL until 6UL) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 12345) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testEmptyULongLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in 6UL until 1UL) {
|
||||||
|
s = s*10 + i.toInt()
|
||||||
|
}
|
||||||
|
if (s != 0) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testULongLoop() {
|
||||||
|
var s = 0
|
||||||
|
for (i in M+1UL until M+6UL) {
|
||||||
|
s = s*10 + (i-M).toInt()
|
||||||
|
}
|
||||||
|
if (s != 12345) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testEmptyULongLoop2() {
|
||||||
|
var s = 0
|
||||||
|
for (i in M+6UL until M+1UL) {
|
||||||
|
s = s*10 + (i-M).toInt()
|
||||||
|
}
|
||||||
|
if (s != 0) throw AssertionError("$s")
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testMaxUItoMinUI() {
|
||||||
|
val xs = ArrayList<UInt>()
|
||||||
|
for (i in MaxUI until MinUI) {
|
||||||
|
xs.add(i)
|
||||||
|
if (xs.size > 23) break
|
||||||
|
}
|
||||||
|
if (xs.size > 0) {
|
||||||
|
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun testMaxULtoMinUL() {
|
||||||
|
val xs = ArrayList<ULong>()
|
||||||
|
for (i in MaxUL until MinUL) {
|
||||||
|
xs.add(i)
|
||||||
|
if (xs.size > 23) break
|
||||||
|
}
|
||||||
|
if (xs.size > 0) {
|
||||||
|
throw AssertionError("Wrong elements for MaxUI..MinUI: $xs")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
testSimpleUIntLoop()
|
||||||
|
testEmptyUIntLoop()
|
||||||
|
testSimpleULongLoop()
|
||||||
|
testEmptyULongLoop()
|
||||||
|
testULongLoop()
|
||||||
|
testEmptyULongLoop2()
|
||||||
|
testMaxUItoMinUI()
|
||||||
|
testMaxULtoMinUL()
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// IGNORE_BACKEND: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
const val MaxUI = UInt.MAX_VALUE
|
||||||
|
const val MinUI = UInt.MIN_VALUE
|
||||||
|
|
||||||
|
const val MaxUL = ULong.MAX_VALUE
|
||||||
|
const val MinUL = ULong.MIN_VALUE
|
||||||
|
|
||||||
|
val M1 = MaxUI.toULong()
|
||||||
|
val M2 = M1 + 10UL
|
||||||
|
|
||||||
|
fun box(): String {
|
||||||
|
if (0u in 1u..10u) throw AssertionError()
|
||||||
|
if (1u !in 1u..10u) throw AssertionError()
|
||||||
|
if (5u !in 1u..10u) throw AssertionError()
|
||||||
|
if (10u !in 1u..10u) throw AssertionError()
|
||||||
|
if (20u in 1u..10u) throw AssertionError()
|
||||||
|
|
||||||
|
if (0UL in 1UL..10UL) throw AssertionError()
|
||||||
|
if (1UL !in 1UL..10UL) throw AssertionError()
|
||||||
|
if (5UL !in 1UL..10UL) throw AssertionError()
|
||||||
|
if (10UL !in 1UL..10UL) throw AssertionError()
|
||||||
|
if (20UL in 1UL..10UL) throw AssertionError()
|
||||||
|
|
||||||
|
if (0u !in MinUI..MaxUI) throw AssertionError()
|
||||||
|
if (MinUI !in MinUI..MaxUI) throw AssertionError()
|
||||||
|
if (MaxUI !in MinUI..MaxUI) throw AssertionError()
|
||||||
|
|
||||||
|
if (0UL !in MinUL..MaxUL) throw AssertionError()
|
||||||
|
if (MinUL !in MinUL..MaxUL) throw AssertionError()
|
||||||
|
if (MaxUL !in MinUL..MaxUL) throw AssertionError()
|
||||||
|
|
||||||
|
if (0UL in M1..M2) throw AssertionError()
|
||||||
|
if (1UL in M1..M2) throw AssertionError()
|
||||||
|
if (10UL in M1..M2) throw AssertionError()
|
||||||
|
if (M1 !in M1..M2) throw AssertionError()
|
||||||
|
if (M1+1UL !in M1..M2) throw AssertionError()
|
||||||
|
if (M2 !in M1..M2) throw AssertionError()
|
||||||
|
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
+20
@@ -24193,6 +24193,26 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedDownTo.kt")
|
||||||
|
public void testForInUnsignedDownTo() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedDownTo.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedRangeLiteral.kt")
|
||||||
|
public void testForInUnsignedRangeLiteral() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedRangeLiteral.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedUntil.kt")
|
||||||
|
public void testForInUnsignedUntil() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inUnsignedRangeLiteral.kt")
|
||||||
|
public void testInUnsignedRangeLiteral() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRangeLiteral.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||||
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||||
|
|||||||
+20
@@ -24193,6 +24193,26 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedDownTo.kt")
|
||||||
|
public void testForInUnsignedDownTo() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedDownTo.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedRangeLiteral.kt")
|
||||||
|
public void testForInUnsignedRangeLiteral() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedRangeLiteral.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedUntil.kt")
|
||||||
|
public void testForInUnsignedUntil() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inUnsignedRangeLiteral.kt")
|
||||||
|
public void testInUnsignedRangeLiteral() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRangeLiteral.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||||
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||||
|
|||||||
+20
@@ -24198,6 +24198,26 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedDownTo.kt")
|
||||||
|
public void testForInUnsignedDownTo() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedDownTo.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedRangeLiteral.kt")
|
||||||
|
public void testForInUnsignedRangeLiteral() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedRangeLiteral.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedUntil.kt")
|
||||||
|
public void testForInUnsignedUntil() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inUnsignedRangeLiteral.kt")
|
||||||
|
public void testInUnsignedRangeLiteral() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRangeLiteral.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||||
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||||
|
|||||||
+20
@@ -18643,6 +18643,26 @@ public class IrJsCodegenBoxTestGenerated extends AbstractIrJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedDownTo.kt")
|
||||||
|
public void testForInUnsignedDownTo() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedDownTo.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedRangeLiteral.kt")
|
||||||
|
public void testForInUnsignedRangeLiteral() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedRangeLiteral.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedUntil.kt")
|
||||||
|
public void testForInUnsignedUntil() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inUnsignedRangeLiteral.kt")
|
||||||
|
public void testInUnsignedRangeLiteral() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRangeLiteral.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||||
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||||
|
|||||||
+20
@@ -19693,6 +19693,26 @@ public class JsCodegenBoxTestGenerated extends AbstractJsCodegenBoxTest {
|
|||||||
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/forEachIndexedInListOfUInts.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedDownTo.kt")
|
||||||
|
public void testForInUnsignedDownTo() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedDownTo.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedRangeLiteral.kt")
|
||||||
|
public void testForInUnsignedRangeLiteral() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedRangeLiteral.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("forInUnsignedUntil.kt")
|
||||||
|
public void testForInUnsignedUntil() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/forInUnsignedUntil.kt");
|
||||||
|
}
|
||||||
|
|
||||||
|
@TestMetadata("inUnsignedRangeLiteral.kt")
|
||||||
|
public void testInUnsignedRangeLiteral() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/unsignedTypes/inUnsignedRangeLiteral.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
@TestMetadata("iterateOverArrayOfUnsignedValues.kt")
|
||||||
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
public void testIterateOverArrayOfUnsignedValues() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
runTest("compiler/testData/codegen/box/unsignedTypes/iterateOverArrayOfUnsignedValues.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user