From 62b774b2e32112a2b5316f598f6f53f248f895ac Mon Sep 17 00:00:00 2001 From: Dmitriy Novozhilov Date: Wed, 10 Nov 2021 16:09:58 +0300 Subject: [PATCH] [FE 1.0] Properly report INTEGER_OPERATOR_RESOLVE_WILL_CHANGE ^KT-38895 --- ...chemeOfIntegerOperatorResolutionChecker.kt | 32 +++++++------- .../parameters/expressions/divide.kt | 2 +- .../parameters/expressions/intrincics.kt | 2 +- .../parameters/expressions/maxValueByte.kt | 2 +- .../parameters/expressions/miltiply.kt | 2 +- .../parameters/expressions/minus.kt | 2 +- .../annotations/parameters/expressions/mod.kt | 2 +- .../parameters/expressions/plus.kt | 2 +- .../tests/evaluate/binaryMinusDepOnExpType.kt | 22 +++++----- .../evaluate/binaryMinusIndependentExpType.kt | 22 +++++----- .../tests/evaluate/divisionByZero.kt | 2 +- .../constructorOfUnsignedType.kt | 2 +- .../tests/evaluate/numberBinaryOperations.kt | 16 +++---- .../evaluate/numberBinaryOperationsCall.kt | 16 +++---- .../numberBinaryOperationsInfixCall.kt | 16 +++---- .../diagnostics/tests/numbers/kt47729.fir.kt | 6 +-- .../diagnostics/tests/numbers/kt47729.kt | 6 +-- .../tests/numbers/kt47729_parenthesis.fir.kt | 4 +- .../tests/numbers/kt47729_parenthesis.kt | 16 +++---- .../tests/numbers/kt48361_disabled.fir.kt | 2 +- .../tests/numbers/kt48361_disabled.kt | 6 +-- .../literalReceiverWithIntegerValueType.kt | 20 ++++----- ...wLiteralOperatorsResolution_warning.fir.kt | 8 ++-- .../newLiteralOperatorsResolution_warning.kt | 42 +++++++++---------- .../tests/operatorRem/numberRemConversions.kt | 4 +- .../kotlin/config/LanguageVersionSettings.kt | 1 - 26 files changed, 126 insertions(+), 131 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt index 6d09e11bdc9..492822ed2a2 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/checkers/NewSchemeOfIntegerOperatorResolutionChecker.kt @@ -10,6 +10,7 @@ import org.jetbrains.kotlin.config.LanguageFeature import org.jetbrains.kotlin.config.LanguageVersionSettings import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor +import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.diagnostics.Errors import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.name.FqName @@ -19,23 +20,20 @@ import org.jetbrains.kotlin.psi.KtPsiUtil import org.jetbrains.kotlin.psi.KtUnaryExpression import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.resolve.BindingTrace -import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall import org.jetbrains.kotlin.resolve.calls.components.isVararg import org.jetbrains.kotlin.resolve.calls.model.ResolvedCall +import org.jetbrains.kotlin.resolve.calls.util.getResolvedCall import org.jetbrains.kotlin.resolve.constants.ErrorValue import org.jetbrains.kotlin.resolve.constants.IntegerLiteralTypeConstructor import org.jetbrains.kotlin.resolve.constants.IntegerValueTypeConstant import org.jetbrains.kotlin.resolve.constants.TypedCompileTimeConstant import org.jetbrains.kotlin.resolve.descriptorUtil.fqNameSafe -import org.jetbrains.kotlin.types.KotlinType -import org.jetbrains.kotlin.types.SimpleType -import org.jetbrains.kotlin.types.lowerIfFlexible -import org.jetbrains.kotlin.types.typeUtil.isPrimitiveNumberOrNullableType -import org.jetbrains.kotlin.types.typeUtil.makeNotNullable +import org.jetbrains.kotlin.types.* +import org.jetbrains.kotlin.types.typeUtil.* object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker { override fun check(resolvedCall: ResolvedCall<*>, reportOn: PsiElement, context: CallCheckerContext) { - if (!context.languageVersionSettings.needReport()) return + if (context.languageVersionSettings.supportsFeature(LanguageFeature.ApproximateIntegerLiteralTypesInReceiverPosition)) return for ((valueParameter, arguments) in resolvedCall.valueArguments) { val expectedType = if (valueParameter.isVararg) { valueParameter.varargElementType ?: continue @@ -52,11 +50,6 @@ object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker { } } - private fun LanguageVersionSettings.needReport(): Boolean { - return supportsFeature(LanguageFeature.ReportChangingIntegerOperatorResolve) && - !supportsFeature(LanguageFeature.ApproximateIntegerLiteralTypesInReceiverPosition) - } - @JvmStatic fun checkArgument( expectedType: KotlinType, @@ -65,7 +58,7 @@ object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker { trace: BindingTrace, moduleDescriptor: ModuleDescriptor ) { - if (!languageVersionSettings.needReport()) return + if (languageVersionSettings.supportsFeature(LanguageFeature.ApproximateIntegerLiteralTypesInReceiverPosition)) return val type = expectedType.lowerIfFlexible() if (type.isPrimitiveNumberOrNullableType()) { checkArgumentImpl(type, KtPsiUtil.deparenthesize(argument)!!, trace, moduleDescriptor) @@ -91,9 +84,10 @@ object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker { val compileTimeValue = bindingContext[BindingContext.COMPILE_TIME_VALUE, argumentExpression] ?: return - val expressionType = when (compileTimeValue) { + val newExpressionType = when (compileTimeValue) { is IntegerValueTypeConstant -> { - val valueTypeConstructor = compileTimeValue.unknownIntegerType.constructor as? IntegerLiteralTypeConstructor ?: return + val currentExpressionType = compileTimeValue.unknownIntegerType + val valueTypeConstructor = currentExpressionType.constructor as? IntegerLiteralTypeConstructor ?: return valueTypeConstructor.getApproximatedType() } is TypedCompileTimeConstant -> { @@ -110,8 +104,11 @@ object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker { } else -> return } - if (expressionType.constructor != expectedType.constructor) { - trace.report(Errors.INTEGER_OPERATOR_RESOLVE_WILL_CHANGE.on(argumentExpression, expressionType)) + if (newExpressionType.constructor != expectedType.constructor) { + val willBeConversion = newExpressionType.isInt() && expectedType.makeNotNullable().isLong() + if (!willBeConversion) { + trace.report(Errors.INTEGER_OPERATOR_RESOLVE_WILL_CHANGE.on(argumentExpression, newExpressionType)) + } } } @@ -125,6 +122,5 @@ object NewSchemeOfIntegerOperatorResolutionChecker : CallChecker { "times", "div", "rem", "shl", "shr", "ushr", "and", "or", "xor", "unaryPlus", "unaryMinus", "inv", ).mapTo(mutableSetOf()) { FqName.fromSegments(listOf("kotlin", "Int", it)) } - } diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/divide.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/divide.kt index 3adade0074a..11bd9d7e6f5 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/divide.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/divide.kt @@ -8,6 +8,6 @@ annotation class Ann( val l: Long ) -@Ann(1 / 1, 1 / 1, 1 / 1, 1 / 1) class MyClass +@Ann(1 / 1, 1 / 1, 1 / 1, 1 / 1) class MyClass // EXPECTED: @Ann(b = 1.toByte(), i = 1, l = 1.toLong(), s = 1.toShort()) diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/intrincics.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/intrincics.kt index ffb752c2ee5..c036d1b8f7e 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/intrincics.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/intrincics.kt @@ -9,6 +9,6 @@ annotation class Ann(p1: Int, p6: Int ) -@Ann(1 or 1, 1 and 1, 1 xor 1, 1 shl 1, 1 shr 1, 1 ushr 1) class MyClass +@Ann(1 or 1, 1 and 1, 1 xor 1, 1 shl 1, 1 shr 1, 1 ushr 1) class MyClass // EXPECTED: @Ann(p1 = 1, p2 = 1.toShort(), p3 = 0.toByte(), p4 = 2, p5 = 0, p6 = 0) diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/maxValueByte.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/maxValueByte.kt index 9ba847e2018..8146d177798 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/maxValueByte.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/maxValueByte.kt @@ -11,7 +11,7 @@ annotation class Ann( @Ann( p1 = java.lang.Byte.MAX_VALUE + 1, - p2 = 1 + 1, + p2 = 1 + 1, p3 = java.lang.Byte.MAX_VALUE + 1, p4 = 1.toByte() + 1.toByte(), p5 = 1.toByte() + 1.toByte() diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/miltiply.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/miltiply.kt index 894d588eed9..b0927efc7e8 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/miltiply.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/miltiply.kt @@ -8,6 +8,6 @@ annotation class Ann( val l: Long ) -@Ann(1 * 1, 1 * 1, 1 * 1, 1 * 1) class MyClass +@Ann(1 * 1, 1 * 1, 1 * 1, 1 * 1) class MyClass // EXPECTED: @Ann(b = 1.toByte(), i = 1, l = 1.toLong(), s = 1.toShort()) diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/minus.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/minus.kt index c2df3c72afe..02b1ceff496 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/minus.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/minus.kt @@ -8,6 +8,6 @@ annotation class Ann( val l: Long ) -@Ann(1 - 1, 1 - 1, 1 - 1, 1 - 1) class MyClass +@Ann(1 - 1, 1 - 1, 1 - 1, 1 - 1) class MyClass // EXPECTED: @Ann(b = 0.toByte(), i = 0, l = 0.toLong(), s = 0.toShort()) diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/mod.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/mod.kt index 35d805d2d1c..abe756cac99 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/mod.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/mod.kt @@ -8,6 +8,6 @@ annotation class Ann( val l: Long ) -@Ann(1 % 1, 1 % 1, 1 % 1, 1 % 1) class MyClass +@Ann(1 % 1, 1 % 1, 1 % 1, 1 % 1) class MyClass // EXPECTED: @Ann(b = 0.toByte(), i = 0, l = 0.toLong(), s = 0.toShort()) diff --git a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/plus.kt b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/plus.kt index 2a281baec23..a7f76b6801c 100644 --- a/compiler/testData/diagnostics/tests/annotations/parameters/expressions/plus.kt +++ b/compiler/testData/diagnostics/tests/annotations/parameters/expressions/plus.kt @@ -8,6 +8,6 @@ annotation class Ann( val l: Long ) -@Ann(1 + 1, 1 + 1, 1 + 1, 1 + 1) class MyClass +@Ann(1 + 1, 1 + 1, 1 + 1, 1 + 1) class MyClass // EXPECTED: @Ann(b = 2.toByte(), i = 2, l = 2.toLong(), s = 2.toShort()) diff --git a/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.kt b/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.kt index 12ac32fb30f..62403c8160b 100644 --- a/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.kt +++ b/compiler/testData/diagnostics/tests/evaluate/binaryMinusDepOnExpType.kt @@ -8,14 +8,14 @@ fun test() { fooInt(1 - 1) fooInt(1 - 1.toInt()) fooInt(1 - 1.toByte()) - fooInt(1 - 1.toLong()) + fooInt(1 - 1.toLong()) fooInt(1 - 1.toShort()) - fooByte(1 - 1) - fooByte(1 - 1.toInt()) - fooByte(1 - 1.toByte()) - fooByte(1 - 1.toLong()) - fooByte(1 - 1.toShort()) + fooByte(1 - 1) + fooByte(1 - 1.toInt()) + fooByte(1 - 1.toByte()) + fooByte(1 - 1.toLong()) + fooByte(1 - 1.toShort()) fooLong(1 - 1) fooLong(1 - 1.toInt()) @@ -23,9 +23,9 @@ fun test() { fooLong(1 - 1.toLong()) fooLong(1 - 1.toShort()) - fooShort(1 - 1) - fooShort(1 - 1.toInt()) - fooShort(1 - 1.toByte()) - fooShort(1 - 1.toLong()) - fooShort(1 - 1.toShort()) + fooShort(1 - 1) + fooShort(1 - 1.toInt()) + fooShort(1 - 1.toByte()) + fooShort(1 - 1.toLong()) + fooShort(1 - 1.toShort()) } diff --git a/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.kt b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.kt index 6fa87294214..cc87c043e12 100644 --- a/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.kt +++ b/compiler/testData/diagnostics/tests/evaluate/binaryMinusIndependentExpType.kt @@ -1,24 +1,24 @@ val p1: Int = 1 - 1 val p2: Long = 1 - 1 -val p3: Byte = 1 - 1 -val p4: Short = 1 - 1 +val p3: Byte = 1 - 1 +val p4: Short = 1 - 1 val l1: Long = 1 - 1.toLong() -val l2: Byte = 1 - 1.toLong() -val l3: Int = 1 - 1.toLong() -val l4: Short = 1 - 1.toLong() +val l2: Byte = 1 - 1.toLong() +val l3: Int = 1 - 1.toLong() +val l4: Short = 1 - 1.toLong() -val b1: Byte = 1 - 1.toByte() +val b1: Byte = 1 - 1.toByte() val b2: Int = 1 - 1.toByte() val b3: Long = 1 - 1.toByte() -val b4: Short = 1 - 1.toByte() +val b4: Short = 1 - 1.toByte() -val i1: Byte = 1 - 1.toInt() +val i1: Byte = 1 - 1.toInt() val i2: Int = 1 - 1.toInt() val i3: Long = 1 - 1.toInt() -val i4: Short = 1 - 1.toInt() +val i4: Short = 1 - 1.toInt() -val s1: Byte = 1 - 1.toShort() +val s1: Byte = 1 - 1.toShort() val s2: Int = 1 - 1.toShort() val s3: Long = 1 - 1.toShort() -val s4: Short = 1 - 1.toShort() +val s4: Short = 1 - 1.toShort() diff --git a/compiler/testData/diagnostics/tests/evaluate/divisionByZero.kt b/compiler/testData/diagnostics/tests/evaluate/divisionByZero.kt index cbf3914065e..ab83e4bba4b 100644 --- a/compiler/testData/diagnostics/tests/evaluate/divisionByZero.kt +++ b/compiler/testData/diagnostics/tests/evaluate/divisionByZero.kt @@ -15,7 +15,7 @@ val a10 = 1 / 0.0f val a11 = 1 / 0.0 val a12 = 1L / 0 -val b1: Byte = 1 / 0 +val b1: Byte = 1 / 0 @Ann(1 / 0) val b2 = 1 annotation class Ann(val i : Int) diff --git a/compiler/testData/diagnostics/tests/evaluate/inlineClasses/constructorOfUnsignedType.kt b/compiler/testData/diagnostics/tests/evaluate/inlineClasses/constructorOfUnsignedType.kt index d4c13ae6a0e..a2acf2dbae3 100644 --- a/compiler/testData/diagnostics/tests/evaluate/inlineClasses/constructorOfUnsignedType.kt +++ b/compiler/testData/diagnostics/tests/evaluate/inlineClasses/constructorOfUnsignedType.kt @@ -29,7 +29,7 @@ const val ui2 = UInt(40 + 2) @AnnoUB(UByte(1), ub0) fun f0() {} -@AnnoUS(UShort(2 + 5), us0) +@AnnoUS(UShort(2 + 5), us0) fun f1() {} @AnnoUI(ui0, ui1, ui2, UInt(100)) diff --git a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.kt b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.kt index 22f1e5988ea..dc230fa136a 100644 --- a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.kt +++ b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperations.kt @@ -6,22 +6,22 @@ fun fooShort(p: Short) = p fun test() { fooInt(1 + 1) - fooByte(1 + 1) + fooByte(1 + 1) fooLong(1 + 1) - fooShort(1 + 1) + fooShort(1 + 1) fooInt(1 * 1) - fooByte(1 * 1) + fooByte(1 * 1) fooLong(1 * 1) - fooShort(1 * 1) + fooShort(1 * 1) fooInt(1 / 1) - fooByte(1 / 1) + fooByte(1 / 1) fooLong(1 / 1) - fooShort(1 / 1) + fooShort(1 / 1) fooInt(1 % 1) - fooByte(1 % 1) + fooByte(1 % 1) fooLong(1 % 1) - fooShort(1 % 1) + fooShort(1 % 1) } diff --git a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.kt b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.kt index 6adb0fd64e6..45f43d4a08a 100644 --- a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.kt +++ b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsCall.kt @@ -6,22 +6,22 @@ fun fooShort(p: Short) = p fun test() { fooInt(1.plus(1)) - fooByte(1.plus(1)) + fooByte(1.plus(1)) fooLong(1.plus(1)) - fooShort(1.plus(1)) + fooShort(1.plus(1)) fooInt(1.times(1)) - fooByte(1.times(1)) + fooByte(1.times(1)) fooLong(1.times(1)) - fooShort(1.times(1)) + fooShort(1.times(1)) fooInt(1.div(1)) - fooByte(1.div(1)) + fooByte(1.div(1)) fooLong(1.div(1)) - fooShort(1.div(1)) + fooShort(1.div(1)) fooInt(1.rem(1)) - fooByte(1.rem(1)) + fooByte(1.rem(1)) fooLong(1.rem(1)) - fooShort(1.rem(1)) + fooShort(1.rem(1)) } diff --git a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.kt b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.kt index 10479156025..ed1d6e1e8e4 100644 --- a/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.kt +++ b/compiler/testData/diagnostics/tests/evaluate/numberBinaryOperationsInfixCall.kt @@ -6,22 +6,22 @@ fun fooShort(p: Short) = p fun test() { fooInt(1 plus 1) - fooByte(1 plus 1) + fooByte(1 plus 1) fooLong(1 plus 1) - fooShort(1 plus 1) + fooShort(1 plus 1) fooInt(1 times 1) - fooByte(1 times 1) + fooByte(1 times 1) fooLong(1 times 1) - fooShort(1 times 1) + fooShort(1 times 1) fooInt(1 div 1) - fooByte(1 div 1) + fooByte(1 div 1) fooLong(1 div 1) - fooShort(1 div 1) + fooShort(1 div 1) fooInt(1 rem 1) - fooByte(1 rem 1) + fooByte(1 rem 1) fooLong(1 rem 1) - fooShort(1 rem 1) + fooShort(1 rem 1) } diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729.fir.kt b/compiler/testData/diagnostics/tests/numbers/kt47729.fir.kt index 93ba4f7974c..a4badca8dae 100644 --- a/compiler/testData/diagnostics/tests/numbers/kt47729.fir.kt +++ b/compiler/testData/diagnostics/tests/numbers/kt47729.fir.kt @@ -1,4 +1,4 @@ -// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // ISSUE: Kt-47447, KT-47729 fun takeLong(value : Long) {} @@ -11,10 +11,10 @@ fun takeGeneric(value : A) {} fun takeGenericX(value : A?) {} fun test_1() { - takeLong(1 + 1) // warning + takeLong(1 + 1) // ok takeInt(1 + 1) // ok takeAny(1 + 1) // ok - takeLongX(1 + 1) // warning + takeLongX(1 + 1) // ok takeIntX(1 + 1) // ok takeAnyX(1 + 1) // ok takeGeneric(1 + 1) // ok diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729.kt b/compiler/testData/diagnostics/tests/numbers/kt47729.kt index d77f86cf94b..f7ff85b005d 100644 --- a/compiler/testData/diagnostics/tests/numbers/kt47729.kt +++ b/compiler/testData/diagnostics/tests/numbers/kt47729.kt @@ -1,4 +1,4 @@ -// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // ISSUE: Kt-47447, KT-47729 fun takeLong(value : Long) {} @@ -11,10 +11,10 @@ fun takeGeneric(value : A) {} fun takeGenericX(value : A?) {} fun test_1() { - takeLong(1 + 1) // warning + takeLong(1 + 1) // ok takeInt(1 + 1) // ok takeAny(1 + 1) // ok - takeLongX(1 + 1) // warning + takeLongX(1 + 1) // ok takeIntX(1 + 1) // ok takeAnyX(1 + 1) // ok takeGeneric(1 + 1) // ok diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.fir.kt b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.fir.kt index 6ec277eafca..8b2f1d2fd79 100644 --- a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.fir.kt +++ b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.fir.kt @@ -1,4 +1,4 @@ -// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // ISSUE: Kt-47447, KT-47729 fun takeLong(x: Long) {} @@ -9,7 +9,7 @@ object Foo { infix fun infixOperator(x: Long) {} } -// Should be warning in all places +// Should be ok in all places fun test() { takeLong(1 + 1) takeLong((1 + 1)) diff --git a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt index 7953e1808e8..df992e251ce 100644 --- a/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt +++ b/compiler/testData/diagnostics/tests/numbers/kt47729_parenthesis.kt @@ -1,4 +1,4 @@ -// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // ISSUE: Kt-47447, KT-47729 fun takeLong(x: Long) {} @@ -9,12 +9,12 @@ object Foo { infix fun infixOperator(x: Long) {} } -// Should be warning in all places +// Should be ok in all places fun test() { - takeLong(1 + 1) - takeLong((1 + 1)) - Foo.longProperty = 1 + 1 - Foo.longProperty = (1 + 1) - Foo infixOperator 1 + 1 - Foo infixOperator (1 + 1) + takeLong(1 + 1) + takeLong((1 + 1)) + Foo.longProperty = 1 + 1 + Foo.longProperty = (1 + 1) + Foo infixOperator 1 + 1 + Foo infixOperator (1 + 1) } diff --git a/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt index 90f1ff784be..cd4a8c44a46 100644 --- a/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt +++ b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.fir.kt @@ -1,4 +1,4 @@ -// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve +// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition fun foo(ttlMillis: Long = 5 * 60 * 1000) {} diff --git a/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt index 77ed8f93dab..7406c755b3b 100644 --- a/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt +++ b/compiler/testData/diagnostics/tests/numbers/kt48361_disabled.kt @@ -1,5 +1,5 @@ -// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve +// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition -fun foo(ttlMillis: Long = 5 * 60 * 1000) {} +fun foo(ttlMillis: Long = 5 * 60 * 1000) {} -const val cacheSize: Long = 4096 * 4 +const val cacheSize: Long = 4096 * 4 diff --git a/compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt b/compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt index 76305f242e7..677695477fe 100644 --- a/compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt +++ b/compiler/testData/diagnostics/tests/numbers/literalReceiverWithIntegerValueType.kt @@ -26,19 +26,19 @@ fun testLongDotCall(c1: C) { } fun testShortDotCall(c2: C) { - c2.takeT(1.plus(2)) + c2.takeT(1.plus(2)) c2.takeT(1.inc()) c2.takeT(1.dec()) - c2.takeT(1.shr(2)) - c2.takeT(1.inv()) + c2.takeT(1.shr(2)) + c2.takeT(1.inv()) } fun testByteDotCall(c3: C) { - c3.takeT(1.plus(2)) + c3.takeT(1.plus(2)) c3.takeT(1.inc()) c3.takeT(1.dec()) - c3.takeT(1.shr(2)) - c3.takeT(1.inv()) + c3.takeT(1.shr(2)) + c3.takeT(1.inv()) } fun testLongOperatorInfixCall(c4: C) { @@ -58,11 +58,11 @@ fun testLongOperatorInfixCall(c4: C) { } fun testShortOperatorInfixCall(c5: C) { - c5.takeT(1 + 2) - c5.takeT(1 shr 2) + c5.takeT(1 + 2) + c5.takeT(1 shr 2) } fun testByteOperatorInfixCall(c6: C) { - c6.takeT(1 + 2) - c6.takeT(1 shr 2) + c6.takeT(1 + 2) + c6.takeT(1 shr 2) } diff --git a/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.fir.kt b/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.fir.kt index c48e7882c07..7285b3c873c 100644 --- a/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.fir.kt +++ b/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.fir.kt @@ -1,4 +1,4 @@ -// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // WITH_STDLIB // ISSUE: KT-38895 @@ -40,6 +40,7 @@ fun testByteUnaryOperators() { takeByte(1.dec()) } +// all positive fun testLongBinaryOperators() { takeLong(2 + 1) takeLong(2 - 1) @@ -60,7 +61,6 @@ fun testLongBinaryOperators() { takeLong(2 or 1) takeLong(2 xor 1) - // positive takeLong(2 * 100000000000) } @@ -68,11 +68,11 @@ fun testLongUnaryOperators() { // Won't change takeLong(+1) takeLong(-1) - - // Will change takeLong(2.unaryPlus()) takeLong(2.unaryMinus()) takeLong(2.inv()) + + // Will change takeLong(1.inc()) takeLong(1.dec()) } diff --git a/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.kt b/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.kt index abab1c413fb..ec39fa20a7e 100644 --- a/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.kt +++ b/compiler/testData/diagnostics/tests/numbers/newLiteralOperatorsResolution_warning.kt @@ -1,4 +1,4 @@ -// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve +// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition // WITH_STDLIB // ISSUE: KT-38895 @@ -40,27 +40,27 @@ fun testByteUnaryOperators() { takeByte(1.dec()) } +// all positive fun testLongBinaryOperators() { - takeLong(2 + 1) - takeLong(2 - 1) - takeLong(2 * 1) - takeLong(2 / 1) - takeLong(2 % 1) + takeLong(2 + 1) + takeLong(2 - 1) + takeLong(2 * 1) + takeLong(2 / 1) + takeLong(2 % 1) - takeLong(2.plus(1)) - takeLong(2.minus(1)) - takeLong(2.times(1)) - takeLong(2.div(1)) - takeLong(2.rem(1)) - takeLong(2 shl 1) - takeLong(2 shr 1) - takeLong(2 ushr 1) + takeLong(2.plus(1)) + takeLong(2.minus(1)) + takeLong(2.times(1)) + takeLong(2.div(1)) + takeLong(2.rem(1)) + takeLong(2 shl 1) + takeLong(2 shr 1) + takeLong(2 ushr 1) - takeLong(2 and 1) - takeLong(2 or 1) - takeLong(2 xor 1) + takeLong(2 and 1) + takeLong(2 or 1) + takeLong(2 xor 1) - // positive takeLong(2 * 100000000000) } @@ -68,11 +68,11 @@ fun testLongUnaryOperators() { // Won't change takeLong(+1) takeLong(-1) + takeLong(2.unaryPlus()) + takeLong(2.unaryMinus()) + takeLong(2.inv()) // Will change - takeLong(2.unaryPlus()) - takeLong(2.unaryMinus()) - takeLong(2.inv()) takeLong(1.inc()) takeLong(1.dec()) } diff --git a/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.kt b/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.kt index 468608b6a21..b4d99fcf306 100644 --- a/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.kt +++ b/compiler/testData/diagnostics/tests/operatorRem/numberRemConversions.kt @@ -7,9 +7,9 @@ fun fooShort(p: Short) = p fun test() { fooInt(1 % 1) - fooByte(1 % 1) + fooByte(1 % 1) fooLong(1 % 1) - fooShort(1 % 1) + fooShort(1 % 1) } public operator fun Int.rem(other: Int): Int = 0 diff --git a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt index c524a103880..f08b8131a84 100644 --- a/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt +++ b/compiler/util/src/org/jetbrains/kotlin/config/LanguageVersionSettings.kt @@ -249,7 +249,6 @@ enum class LanguageFeature( // Disabled for indefinite time. See KT-48535 and related discussion OptInOnOverrideForbidden(sinceVersion = null, kind = BUG_FIX), ApproximateIntegerLiteralTypesInReceiverPosition(sinceVersion = null), - ReportChangingIntegerOperatorResolve(sinceVersion = null), // Experimental features