[FE 1.0] Properly report INTEGER_OPERATOR_RESOLVE_WILL_CHANGE
^KT-38895
This commit is contained in:
committed by
teamcity
parent
21444d6be8
commit
62b774b2e3
+14
-18
@@ -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)) }
|
||||
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@ annotation class Ann(
|
||||
val l: Long
|
||||
)
|
||||
|
||||
@Ann(1 / 1, 1 / 1, 1 / 1, 1 / 1) class MyClass
|
||||
@Ann(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 / 1<!>, <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 / 1<!>, 1 / 1, 1 / 1) class MyClass
|
||||
|
||||
// EXPECTED: @Ann(b = 1.toByte(), i = 1, l = 1.toLong(), s = 1.toShort())
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@ annotation class Ann(<!MISSING_VAL_ON_ANNOTATION_PARAMETER!>p1: Int<!>,
|
||||
<!MISSING_VAL_ON_ANNOTATION_PARAMETER!>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, <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 and 1<!>, <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>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)
|
||||
|
||||
+1
-1
@@ -11,7 +11,7 @@ annotation class Ann(
|
||||
|
||||
@Ann(
|
||||
p1 = <!TYPE_MISMATCH!>java.lang.Byte.MAX_VALUE + 1<!>,
|
||||
p2 = 1 + 1,
|
||||
p2 = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>,
|
||||
p3 = java.lang.Byte.MAX_VALUE + 1,
|
||||
p4 = 1.toByte() + 1.toByte(),
|
||||
p5 = <!TYPE_MISMATCH!>1.toByte() + 1.toByte()<!>
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@ annotation class Ann(
|
||||
val l: Long
|
||||
)
|
||||
|
||||
@Ann(1 * 1, 1 * 1, 1 * 1, 1 * 1) class MyClass
|
||||
@Ann(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 * 1<!>, <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 * 1<!>, 1 * 1, 1 * 1) class MyClass
|
||||
|
||||
// EXPECTED: @Ann(b = 1.toByte(), i = 1, l = 1.toLong(), s = 1.toShort())
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@ annotation class Ann(
|
||||
val l: Long
|
||||
)
|
||||
|
||||
@Ann(1 - 1, 1 - 1, 1 - 1, 1 - 1) class MyClass
|
||||
@Ann(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 - 1<!>, <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 - 1<!>, 1 - 1, 1 - 1) class MyClass
|
||||
|
||||
// EXPECTED: @Ann(b = 0.toByte(), i = 0, l = 0.toLong(), s = 0.toShort())
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@ annotation class Ann(
|
||||
val l: Long
|
||||
)
|
||||
|
||||
@Ann(1 % 1, 1 % 1, 1 % 1, 1 % 1) class MyClass
|
||||
@Ann(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 % 1<!>, <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 % 1<!>, 1 % 1, 1 % 1) class MyClass
|
||||
|
||||
// EXPECTED: @Ann(b = 0.toByte(), i = 0, l = 0.toLong(), s = 0.toShort())
|
||||
|
||||
+1
-1
@@ -8,6 +8,6 @@ annotation class Ann(
|
||||
val l: Long
|
||||
)
|
||||
|
||||
@Ann(1 + 1, 1 + 1, 1 + 1, 1 + 1) class MyClass
|
||||
@Ann(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>, <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>, 1 + 1, 1 + 1) class MyClass
|
||||
|
||||
// EXPECTED: @Ann(b = 2.toByte(), i = 2, l = 2.toLong(), s = 2.toShort())
|
||||
|
||||
@@ -8,14 +8,14 @@ fun test() {
|
||||
fooInt(1 - 1)
|
||||
fooInt(1 - 1.toInt())
|
||||
fooInt(1 - 1.toByte())
|
||||
fooInt(<!TYPE_MISMATCH!>1 - 1.toLong()<!>)
|
||||
fooInt(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toLong()<!>)
|
||||
fooInt(1 - 1.toShort())
|
||||
|
||||
fooByte(1 - 1)
|
||||
fooByte(<!TYPE_MISMATCH!>1 - 1.toInt()<!>)
|
||||
fooByte(<!TYPE_MISMATCH!>1 - 1.toByte()<!>)
|
||||
fooByte(<!TYPE_MISMATCH!>1 - 1.toLong()<!>)
|
||||
fooByte(<!TYPE_MISMATCH!>1 - 1.toShort()<!>)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 - 1<!>)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toInt()<!>)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toByte()<!>)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toLong()<!>)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toShort()<!>)
|
||||
|
||||
fooLong(1 - 1)
|
||||
fooLong(<!TYPE_MISMATCH!>1 - 1.toInt()<!>)
|
||||
@@ -23,9 +23,9 @@ fun test() {
|
||||
fooLong(1 - 1.toLong())
|
||||
fooLong(<!TYPE_MISMATCH!>1 - 1.toShort()<!>)
|
||||
|
||||
fooShort(1 - 1)
|
||||
fooShort(<!TYPE_MISMATCH!>1 - 1.toInt()<!>)
|
||||
fooShort(<!TYPE_MISMATCH!>1 - 1.toByte()<!>)
|
||||
fooShort(<!TYPE_MISMATCH!>1 - 1.toLong()<!>)
|
||||
fooShort(<!TYPE_MISMATCH!>1 - 1.toShort()<!>)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 - 1<!>)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toInt()<!>)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toByte()<!>)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toLong()<!>)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toShort()<!>)
|
||||
}
|
||||
|
||||
+11
-11
@@ -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 = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 - 1<!>
|
||||
val p4: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 - 1<!>
|
||||
|
||||
val l1: Long = 1 - 1.toLong()
|
||||
val l2: Byte = <!TYPE_MISMATCH!>1 - 1.toLong()<!>
|
||||
val l3: Int = <!TYPE_MISMATCH!>1 - 1.toLong()<!>
|
||||
val l4: Short = <!TYPE_MISMATCH!>1 - 1.toLong()<!>
|
||||
val l2: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toLong()<!>
|
||||
val l3: Int = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toLong()<!>
|
||||
val l4: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toLong()<!>
|
||||
|
||||
val b1: Byte = <!TYPE_MISMATCH!>1 - 1.toByte()<!>
|
||||
val b1: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toByte()<!>
|
||||
val b2: Int = 1 - 1.toByte()
|
||||
val b3: Long = <!TYPE_MISMATCH!>1 - 1.toByte()<!>
|
||||
val b4: Short = <!TYPE_MISMATCH!>1 - 1.toByte()<!>
|
||||
val b4: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toByte()<!>
|
||||
|
||||
val i1: Byte = <!TYPE_MISMATCH!>1 - 1.toInt()<!>
|
||||
val i1: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toInt()<!>
|
||||
val i2: Int = 1 - 1.toInt()
|
||||
val i3: Long = <!TYPE_MISMATCH!>1 - 1.toInt()<!>
|
||||
val i4: Short = <!TYPE_MISMATCH!>1 - 1.toInt()<!>
|
||||
val i4: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toInt()<!>
|
||||
|
||||
val s1: Byte = <!TYPE_MISMATCH!>1 - 1.toShort()<!>
|
||||
val s1: Byte = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toShort()<!>
|
||||
val s2: Int = 1 - 1.toShort()
|
||||
val s3: Long = <!TYPE_MISMATCH!>1 - 1.toShort()<!>
|
||||
val s4: Short = <!TYPE_MISMATCH!>1 - 1.toShort()<!>
|
||||
val s4: Short = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 - 1.toShort()<!>
|
||||
|
||||
@@ -15,7 +15,7 @@ val a10 = <!DIVISION_BY_ZERO!>1 / 0.0f<!>
|
||||
val a11 = <!DIVISION_BY_ZERO!>1 / 0.0<!>
|
||||
val a12 = <!DIVISION_BY_ZERO!>1L / 0<!>
|
||||
|
||||
val b1: Byte = <!DIVISION_BY_ZERO, TYPE_MISMATCH!>1 / 0<!>
|
||||
val b1: Byte = <!DIVISION_BY_ZERO, INTEGER_OPERATOR_RESOLVE_WILL_CHANGE, TYPE_MISMATCH!>1 / 0<!>
|
||||
@Ann(<!ANNOTATION_ARGUMENT_MUST_BE_CONST, DIVISION_BY_ZERO!>1 / 0<!>) val b2 = 1
|
||||
|
||||
annotation class Ann(val i : Int)
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ const val ui2 = UInt(40 + 2)
|
||||
@AnnoUB(UByte(1), ub0)
|
||||
fun f0() {}
|
||||
|
||||
@AnnoUS(UShort(2 + 5), us0)
|
||||
@AnnoUS(UShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2 + 5<!>), us0)
|
||||
fun f1() {}
|
||||
|
||||
@AnnoUI(ui0, ui1, ui2, UInt(100))
|
||||
|
||||
@@ -6,22 +6,22 @@ fun fooShort(p: Short) = p
|
||||
|
||||
fun test() {
|
||||
fooInt(1 + 1)
|
||||
fooByte(1 + 1)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>)
|
||||
fooLong(1 + 1)
|
||||
fooShort(1 + 1)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>)
|
||||
|
||||
fooInt(1 * 1)
|
||||
fooByte(1 * 1)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 * 1<!>)
|
||||
fooLong(1 * 1)
|
||||
fooShort(1 * 1)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 * 1<!>)
|
||||
|
||||
fooInt(1 / 1)
|
||||
fooByte(1 / 1)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 / 1<!>)
|
||||
fooLong(1 / 1)
|
||||
fooShort(1 / 1)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 / 1<!>)
|
||||
|
||||
fooInt(1 % 1)
|
||||
fooByte(1 % 1)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 % 1<!>)
|
||||
fooLong(1 % 1)
|
||||
fooShort(1 % 1)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 % 1<!>)
|
||||
}
|
||||
|
||||
@@ -6,22 +6,22 @@ fun fooShort(p: Short) = p
|
||||
|
||||
fun test() {
|
||||
fooInt(1.plus(1))
|
||||
fooByte(1.plus(1))
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.plus(1)<!>)
|
||||
fooLong(1.plus(1))
|
||||
fooShort(1.plus(1))
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.plus(1)<!>)
|
||||
|
||||
fooInt(1.times(1))
|
||||
fooByte(1.times(1))
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.times(1)<!>)
|
||||
fooLong(1.times(1))
|
||||
fooShort(1.times(1))
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.times(1)<!>)
|
||||
|
||||
fooInt(1.div(1))
|
||||
fooByte(1.div(1))
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.div(1)<!>)
|
||||
fooLong(1.div(1))
|
||||
fooShort(1.div(1))
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.div(1)<!>)
|
||||
|
||||
fooInt(1.rem(1))
|
||||
fooByte(1.rem(1))
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.rem(1)<!>)
|
||||
fooLong(1.rem(1))
|
||||
fooShort(1.rem(1))
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.rem(1)<!>)
|
||||
}
|
||||
|
||||
+8
-8
@@ -6,22 +6,22 @@ fun fooShort(p: Short) = p
|
||||
|
||||
fun test() {
|
||||
fooInt(1 <!INFIX_MODIFIER_REQUIRED!>plus<!> 1)
|
||||
fooByte(1 <!INFIX_MODIFIER_REQUIRED!>plus<!> 1)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 <!INFIX_MODIFIER_REQUIRED!>plus<!> 1<!>)
|
||||
fooLong(1 <!INFIX_MODIFIER_REQUIRED!>plus<!> 1)
|
||||
fooShort(1 <!INFIX_MODIFIER_REQUIRED!>plus<!> 1)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 <!INFIX_MODIFIER_REQUIRED!>plus<!> 1<!>)
|
||||
|
||||
fooInt(1 <!INFIX_MODIFIER_REQUIRED!>times<!> 1)
|
||||
fooByte(1 <!INFIX_MODIFIER_REQUIRED!>times<!> 1)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 <!INFIX_MODIFIER_REQUIRED!>times<!> 1<!>)
|
||||
fooLong(1 <!INFIX_MODIFIER_REQUIRED!>times<!> 1)
|
||||
fooShort(1 <!INFIX_MODIFIER_REQUIRED!>times<!> 1)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 <!INFIX_MODIFIER_REQUIRED!>times<!> 1<!>)
|
||||
|
||||
fooInt(1 <!INFIX_MODIFIER_REQUIRED!>div<!> 1)
|
||||
fooByte(1 <!INFIX_MODIFIER_REQUIRED!>div<!> 1)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 <!INFIX_MODIFIER_REQUIRED!>div<!> 1<!>)
|
||||
fooLong(1 <!INFIX_MODIFIER_REQUIRED!>div<!> 1)
|
||||
fooShort(1 <!INFIX_MODIFIER_REQUIRED!>div<!> 1)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 <!INFIX_MODIFIER_REQUIRED!>div<!> 1<!>)
|
||||
|
||||
fooInt(1 <!INFIX_MODIFIER_REQUIRED!>rem<!> 1)
|
||||
fooByte(1 <!INFIX_MODIFIER_REQUIRED!>rem<!> 1)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 <!INFIX_MODIFIER_REQUIRED!>rem<!> 1<!>)
|
||||
fooLong(1 <!INFIX_MODIFIER_REQUIRED!>rem<!> 1)
|
||||
fooShort(1 <!INFIX_MODIFIER_REQUIRED!>rem<!> 1)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 <!INFIX_MODIFIER_REQUIRED!>rem<!> 1<!>)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve
|
||||
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
|
||||
// ISSUE: Kt-47447, KT-47729
|
||||
|
||||
fun takeLong(value : Long) {}
|
||||
@@ -11,10 +11,10 @@ fun <A> takeGeneric(value : A) {}
|
||||
fun <A> takeGenericX(value : A?) {}
|
||||
|
||||
fun test_1() {
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>1 + 1<!>) // warning
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>1 + 1<!>) // ok
|
||||
takeInt(1 + 1) // ok
|
||||
takeAny(1 + 1) // ok
|
||||
takeLongX(<!ARGUMENT_TYPE_MISMATCH!>1 + 1<!>) // warning
|
||||
takeLongX(<!ARGUMENT_TYPE_MISMATCH!>1 + 1<!>) // ok
|
||||
takeIntX(1 + 1) // ok
|
||||
takeAnyX(1 + 1) // ok
|
||||
takeGeneric(1 + 1) // ok
|
||||
|
||||
+3
-3
@@ -1,4 +1,4 @@
|
||||
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve
|
||||
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
|
||||
// ISSUE: Kt-47447, KT-47729
|
||||
|
||||
fun takeLong(value : Long) {}
|
||||
@@ -11,10 +11,10 @@ fun <A> takeGeneric(value : A) {}
|
||||
fun <A> takeGenericX(value : A?) {}
|
||||
|
||||
fun test_1() {
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>) // warning
|
||||
takeLong(1 + 1) // ok
|
||||
takeInt(1 + 1) // ok
|
||||
takeAny(1 + 1) // ok
|
||||
takeLongX(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>) // warning
|
||||
takeLongX(1 + 1) // ok
|
||||
takeIntX(1 + 1) // ok
|
||||
takeAnyX(1 + 1) // ok
|
||||
takeGeneric(1 + 1) // ok
|
||||
|
||||
@@ -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(<!ARGUMENT_TYPE_MISMATCH!>1 + 1<!>)
|
||||
takeLong((<!ARGUMENT_TYPE_MISMATCH!>1 + 1<!>))
|
||||
|
||||
@@ -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(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>)
|
||||
takeLong((<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>))
|
||||
Foo.longProperty = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>
|
||||
Foo.longProperty = (<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>)
|
||||
Foo infixOperator <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>
|
||||
Foo infixOperator (<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 1<!>)
|
||||
takeLong(1 + 1)
|
||||
takeLong((1 + 1))
|
||||
Foo.longProperty = 1 + 1
|
||||
Foo.longProperty = (1 + 1)
|
||||
Foo infixOperator 1 + 1
|
||||
Foo infixOperator (1 + 1)
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve
|
||||
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
|
||||
|
||||
fun foo(ttlMillis: Long = <!TYPE_MISMATCH!>5 * 60 * 1000<!>) {}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve
|
||||
// !LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
|
||||
|
||||
fun foo(ttlMillis: Long = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>5 * 60 * 1000<!>) {}
|
||||
fun foo(ttlMillis: Long = 5 * 60 * 1000) {}
|
||||
|
||||
const val cacheSize: Long = <!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>4096 * 4<!>
|
||||
const val cacheSize: Long = 4096 * 4
|
||||
|
||||
+10
-10
@@ -26,19 +26,19 @@ fun testLongDotCall(c1: C<Long>) {
|
||||
}
|
||||
|
||||
fun testShortDotCall(c2: C<Short>) {
|
||||
c2.takeT(1.plus(2))
|
||||
c2.takeT(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.plus(2)<!>)
|
||||
c2.takeT(<!TYPE_MISMATCH!>1.inc()<!>)
|
||||
c2.takeT(<!TYPE_MISMATCH!>1.dec()<!>)
|
||||
c2.takeT(1.shr(2))
|
||||
c2.takeT(1.inv())
|
||||
c2.takeT(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.shr(2)<!>)
|
||||
c2.takeT(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.inv()<!>)
|
||||
}
|
||||
|
||||
fun testByteDotCall(c3: C<Byte>) {
|
||||
c3.takeT(1.plus(2))
|
||||
c3.takeT(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.plus(2)<!>)
|
||||
c3.takeT(<!TYPE_MISMATCH!>1.inc()<!>)
|
||||
c3.takeT(<!TYPE_MISMATCH!>1.dec()<!>)
|
||||
c3.takeT(1.shr(2))
|
||||
c3.takeT(1.inv())
|
||||
c3.takeT(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.shr(2)<!>)
|
||||
c3.takeT(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1.inv()<!>)
|
||||
}
|
||||
|
||||
fun testLongOperatorInfixCall(c4: C<Long>) {
|
||||
@@ -58,11 +58,11 @@ fun testLongOperatorInfixCall(c4: C<Long>) {
|
||||
}
|
||||
|
||||
fun testShortOperatorInfixCall(c5: C<Short>) {
|
||||
c5.takeT(1 + 2)
|
||||
c5.takeT(1 shr 2)
|
||||
c5.takeT(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>)
|
||||
c5.takeT(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 shr 2<!>)
|
||||
}
|
||||
|
||||
fun testByteOperatorInfixCall(c6: C<Byte>) {
|
||||
c6.takeT(1 + 2)
|
||||
c6.takeT(1 shr 2)
|
||||
c6.takeT(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 + 2<!>)
|
||||
c6.takeT(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 shr 2<!>)
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve
|
||||
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-38895
|
||||
|
||||
@@ -40,6 +40,7 @@ fun testByteUnaryOperators() {
|
||||
takeByte(<!ARGUMENT_TYPE_MISMATCH!>1.dec()<!>)
|
||||
}
|
||||
|
||||
// all positive
|
||||
fun testLongBinaryOperators() {
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2 + 1<!>)
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2 - 1<!>)
|
||||
@@ -60,7 +61,6 @@ fun testLongBinaryOperators() {
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2 or 1<!>)
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2 xor 1<!>)
|
||||
|
||||
// positive
|
||||
takeLong(2 * 100000000000)
|
||||
}
|
||||
|
||||
@@ -68,11 +68,11 @@ fun testLongUnaryOperators() {
|
||||
// Won't change
|
||||
takeLong(+1)
|
||||
takeLong(-1)
|
||||
|
||||
// Will change
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2.unaryPlus()<!>)
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2.unaryMinus()<!>)
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>2.inv()<!>)
|
||||
|
||||
// Will change
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>1.inc()<!>)
|
||||
takeLong(<!ARGUMENT_TYPE_MISMATCH!>1.dec()<!>)
|
||||
}
|
||||
|
||||
+21
-21
@@ -1,4 +1,4 @@
|
||||
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition +ReportChangingIntegerOperatorResolve
|
||||
// LANGUAGE: -ApproximateIntegerLiteralTypesInReceiverPosition
|
||||
// WITH_STDLIB
|
||||
// ISSUE: KT-38895
|
||||
|
||||
@@ -40,27 +40,27 @@ fun testByteUnaryOperators() {
|
||||
takeByte(<!TYPE_MISMATCH!>1.dec()<!>)
|
||||
}
|
||||
|
||||
// all positive
|
||||
fun testLongBinaryOperators() {
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2 + 1<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2 - 1<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2 * 1<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2 / 1<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2 % 1<!>)
|
||||
takeLong(2 + 1)
|
||||
takeLong(2 - 1)
|
||||
takeLong(2 * 1)
|
||||
takeLong(2 / 1)
|
||||
takeLong(2 % 1)
|
||||
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2.plus(1)<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2.minus(1)<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2.times(1)<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2.div(1)<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2.rem(1)<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2 shl 1<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2 shr 1<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>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(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2 and 1<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2 or 1<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>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(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2.unaryPlus()<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2.unaryMinus()<!>)
|
||||
takeLong(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>2.inv()<!>)
|
||||
takeLong(<!TYPE_MISMATCH!>1.inc()<!>)
|
||||
takeLong(<!TYPE_MISMATCH!>1.dec()<!>)
|
||||
}
|
||||
|
||||
@@ -7,9 +7,9 @@ fun fooShort(p: Short) = p
|
||||
|
||||
fun test() {
|
||||
fooInt(1 % 1)
|
||||
fooByte(1 % 1)
|
||||
fooByte(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 % 1<!>)
|
||||
fooLong(1 % 1)
|
||||
fooShort(1 % 1)
|
||||
fooShort(<!INTEGER_OPERATOR_RESOLVE_WILL_CHANGE!>1 % 1<!>)
|
||||
}
|
||||
|
||||
public operator fun Int.<!EXTENSION_SHADOWED_BY_MEMBER!>rem<!>(other: Int): Int = 0
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user