Compare FP numbers properly when determining if field initializer needed
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
+15
@@ -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"
|
||||
}
|
||||
Generated
+5
@@ -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");
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
+5
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user