diff --git a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt index 23eae6a5294..1cc8cdb5677 100644 --- a/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt +++ b/plugins/kapt3/kapt3-compiler/src/org/jetbrains/kotlin/kapt3/stubs/ClassFileToSourceStubConverter.kt @@ -70,6 +70,7 @@ import org.jetbrains.org.objectweb.asm.Type import org.jetbrains.org.objectweb.asm.tree.* import java.io.File import javax.lang.model.element.ElementKind +import kotlin.math.sign import com.sun.tools.javac.util.List as JavacList class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGeneration, val generateNonExistentClass: Boolean) { @@ -1178,11 +1179,22 @@ class ClassFileToSourceStubConverter(val kaptContext: KaptContextForStubGenerati } private fun convertValueOfPrimitiveTypeOrString(value: Any?): JCExpression? { + fun specialFpValueNumerator(value: Double): Double = if (value.isNaN()) 0.0 else 1.0 * value.sign return when (value) { is Char -> treeMaker.Literal(TypeTag.CHAR, value.toInt()) is Byte -> treeMaker.TypeCast(treeMaker.TypeIdent(TypeTag.BYTE), treeMaker.Literal(TypeTag.INT, value.toInt())) is Short -> treeMaker.TypeCast(treeMaker.TypeIdent(TypeTag.SHORT), treeMaker.Literal(TypeTag.INT, value.toInt())) - is Boolean, is Int, is Long, is Float, is Double, is String -> treeMaker.Literal(value) + is Boolean, is Int, is Long, is String -> treeMaker.Literal(value) + is Float -> + when { + value.isFinite() -> treeMaker.Literal(value) + else -> treeMaker.Binary(Tag.DIV, treeMaker.Literal(specialFpValueNumerator(value.toDouble()).toFloat()), treeMaker.Literal(0.0F)) + } + is Double -> + when { + value.isFinite() -> treeMaker.Literal(value) + else -> treeMaker.Binary(Tag.DIV, treeMaker.Literal(specialFpValueNumerator(value)), treeMaker.Literal(0.0)) + } else -> null } } diff --git a/plugins/kapt3/kapt3-compiler/testData/converter/primitiveTypes.txt b/plugins/kapt3/kapt3-compiler/testData/converter/primitiveTypes.txt index 79a71ee37b8..f63ccb76fbc 100644 --- a/plugins/kapt3/kapt3-compiler/testData/converter/primitiveTypes.txt +++ b/plugins/kapt3/kapt3-compiler/testData/converter/primitiveTypes.txt @@ -21,15 +21,15 @@ public final class PrimitiveTypes { public static final long longMinValue = -9223372036854775808L; public static final long longHex = 4294967295L; public static final float float54 = 5.4F; - private static final float floatMaxValue = 0.0F; - private static final float floatNan = 0.0F; - private static final float floatPositiveInfinity = 0.0F; - private static final float floatNegativeInfinity = 0.0F; + private static final float floatMaxValue = 3.4028235E38F; + private static final float floatNan = 0.0F / 0.0F; + private static final float floatPositiveInfinity = 1.0F / 0.0F; + private static final float floatNegativeInfinity = -1.0F / 0.0F; public static final double double54 = 5.4; - private static final double doubleMaxValue = 0.0; - private static final double doubleNan = 0.0; - private static final double doublePositiveInfinity = 0.0; - private static final double doubleNegativeInfinity = 0.0; + private static final double doubleMaxValue = 1.7976931348623157E308; + private static final double doubleNan = 0.0 / 0.0; + private static final double doublePositiveInfinity = 1.0 / 0.0; + private static final double doubleNegativeInfinity = -1.0 / 0.0; @org.jetbrains.annotations.NotNull() public static final java.lang.String stringHelloWorld = "Hello, world!"; @org.jetbrains.annotations.NotNull()