diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeLiteralRangeValue.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeLiteralRangeValue.kt index db7f4c2e678..d9d52a8aa30 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeLiteralRangeValue.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/range/PrimitiveNumberRangeLiteralRangeValue.kt @@ -113,7 +113,8 @@ private fun ExpressionCodegen.isArraySizeAccess(expression: KtExpression): Boole return when { expression is KtDotQualifiedExpression -> { val selector = expression.selectorExpression - asmType(bindingContext.getType(expression.receiverExpression)!!).sort == Type.ARRAY && + val type = bindingContext.getType(expression.receiverExpression) ?: return false + asmType(type).sort == Type.ARRAY && selector is KtNameReferenceExpression && selector.text == "size" } diff --git a/compiler/testData/codegen/box/controlStructures/forInArray/forInArraySpecializedToUntil.kt b/compiler/testData/codegen/box/controlStructures/forInArray/forInArraySpecializedToUntil.kt index 164bbeb1044..9e1d3ddcc3e 100644 --- a/compiler/testData/codegen/box/controlStructures/forInArray/forInArraySpecializedToUntil.kt +++ b/compiler/testData/codegen/box/controlStructures/forInArray/forInArraySpecializedToUntil.kt @@ -124,6 +124,17 @@ fun checkReversedIntArray(): Boolean { return true } +fun checkIntArrayMethodCallBound(): Boolean { + val intArray = intArrayOf(1, 2, 3) + var start = 0 + var sum = 0 + for (i in 0..Math.min(intArray.size, 10) - 1) { + sum += intArray[i] + } + if (sum != 6) return false + return true +} + fun box(): String { // Check that the specialization of 'for (i in 0..array.size-1)' to 'for (i in 0 until array.size)' does not fail on // any kind of arrays. @@ -139,6 +150,7 @@ fun box(): String { if (!checkWithArrayUpdate()) return "Failure" if (!checkIntArrayMinusArbitraryConstant()) return "Failure" if (!checkReversedIntArray()) return "Failure" + if (!checkIntArrayMethodCallBound()) return "Failure" return "OK" } \ No newline at end of file