Compare FP numbers properly when determining if field initializer needed

This commit is contained in:
Dmitry Petrov
2018-07-20 14:35:49 +03:00
parent 819ffe7117
commit 86e863951e
5 changed files with 32 additions and 2 deletions
@@ -578,10 +578,10 @@ public abstract class MemberCodegen<T extends KtPureElement/* TODO: & KtDeclarat
if (type == Type.SHORT_TYPE && ((Number) value).shortValue() == 0) {
return true;
}
if (type == Type.DOUBLE_TYPE && ((Number) value).doubleValue() == 0d) {
if (type == Type.DOUBLE_TYPE && value.equals(0.0)) {
return true;
}
if (type == Type.FLOAT_TYPE && ((Number) value).floatValue() == 0f) {
if (type == Type.FLOAT_TYPE && value.equals(0.0f)) {
return true;
}
}
@@ -0,0 +1,15 @@
// !LANGUAGE: +NoConstantValueAttributeForNonConstVals
// TARGET_BACKEND: JVM
// WITH_RUNTIME
import kotlin.test.assertEquals
val minus0F = -0.0F
val minus0D = -0.0
fun box(): String {
assertEquals(-0.0F, minus0F)
assertEquals(-0.0, minus0D)
return "OK"
}
@@ -15396,6 +15396,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/properties/const/constValInAnnotationDefault.kt");
}
@TestMetadata("fpNonConstValProperlyInitialized.kt")
public void testFpNonConstValProperlyInitialized() throws Exception {
runTest("compiler/testData/codegen/box/properties/const/fpNonConstValProperlyInitialized.kt");
}
@TestMetadata("interfaceCompanion.kt")
public void testInterfaceCompanion() throws Exception {
runTest("compiler/testData/codegen/box/properties/const/interfaceCompanion.kt");
@@ -15396,6 +15396,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/properties/const/constValInAnnotationDefault.kt");
}
@TestMetadata("fpNonConstValProperlyInitialized.kt")
public void testFpNonConstValProperlyInitialized() throws Exception {
runTest("compiler/testData/codegen/box/properties/const/fpNonConstValProperlyInitialized.kt");
}
@TestMetadata("interfaceCompanion.kt")
public void testInterfaceCompanion() throws Exception {
runTest("compiler/testData/codegen/box/properties/const/interfaceCompanion.kt");
@@ -15396,6 +15396,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/properties/const/constValInAnnotationDefault.kt");
}
@TestMetadata("fpNonConstValProperlyInitialized.kt")
public void testFpNonConstValProperlyInitialized() throws Exception {
runTest("compiler/testData/codegen/box/properties/const/fpNonConstValProperlyInitialized.kt");
}
@TestMetadata("interfaceCompanion.kt")
public void testInterfaceCompanion() throws Exception {
runTest("compiler/testData/codegen/box/properties/const/interfaceCompanion.kt");