Deprecate floating point to integral types lesser than Int #KT-30360
This commit is contained in:
@@ -344,6 +344,10 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
}
|
||||
|
||||
private fun generateConversions(kind: PrimitiveType) {
|
||||
fun isConversionDeprecated(otherKind: PrimitiveType): Boolean {
|
||||
return kind in PrimitiveType.floatingPoint && otherKind in listOf(PrimitiveType.BYTE, PrimitiveType.SHORT)
|
||||
}
|
||||
|
||||
val thisName = kind.capitalized
|
||||
for (otherKind in PrimitiveType.exceptBoolean) {
|
||||
val otherName = otherKind.capitalized
|
||||
@@ -367,6 +371,11 @@ class GeneratePrimitives(out: PrintWriter) : BuiltInsSourceGenerator(out) {
|
||||
" /**\n * Converts this [$thisName] value to [$otherName].\n *\n" + detail.replaceIndent(" ")
|
||||
}
|
||||
out.println(doc)
|
||||
|
||||
if (isConversionDeprecated(otherKind)) {
|
||||
out.println(" @Deprecated(\"Unclear conversion. To achieve the same result convert to Int explicitly and then to $otherName.\", ReplaceWith(\"toInt().to$otherName()\"))")
|
||||
}
|
||||
|
||||
out.println(" public override fun to$otherName(): $otherName")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,7 +27,8 @@ fun generate(): String {
|
||||
val sb = StringBuilder()
|
||||
val p = Printer(sb)
|
||||
p.println(File("license/COPYRIGHT.txt").readText())
|
||||
p.println("@file:Suppress(\"DEPRECATION_ERROR\")")
|
||||
p.println("@file:Suppress(\"DEPRECATION\", \"DEPRECATION_ERROR\")")
|
||||
|
||||
p.println()
|
||||
p.println("package org.jetbrains.kotlin.resolve.constants.evaluate")
|
||||
p.println()
|
||||
|
||||
Reference in New Issue
Block a user