Deprecate floating point to integral types lesser than Int #KT-30360

This commit is contained in:
Abduqodiri Qurbonzoda
2020-01-17 06:07:49 +03:00
parent e459542e6f
commit 1203df7405
14 changed files with 255 additions and 32 deletions
@@ -220,8 +220,12 @@ object RangeOps : TemplateGroupBase() {
signature("to${toType}ExactOrNull()")
returns("$toType?")
val isConversionDeprecated = fromType.isFloatingPoint() && toType in listOf(PrimitiveType.Byte, PrimitiveType.Short)
val conversion = if (isConversionDeprecated) "toInt().to$toType" else "to$toType"
body {
"return if (this in $toType.MIN_VALUE.to$fromType()..$toType.MAX_VALUE.to$fromType()) this.to$toType() else null"
"return if (this in $toType.MIN_VALUE.to$fromType()..$toType.MAX_VALUE.to$fromType()) this.$conversion() else null"
}
}
}