summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--lib.c5
-rw-r--r--tests/custom/04_bugs/30_nan_strict_equality14
-rw-r--r--types.c2
3 files changed, 20 insertions, 1 deletions
diff --git a/lib.c b/lib.c
index 9d7b26a..7b0c9ca 100644
--- a/lib.c
+++ b/lib.c
@@ -2921,6 +2921,11 @@ uc_uniq_ucv_equal(const void *k1, const void *k2)
if (!ucv_is_scalar(uv1) && !ucv_is_scalar(uv2))
return (uv1 == uv2);
+ /* for the sake of array item uniqueness, treat two NaNs as equal */
+ if (ucv_type(uv1) == UC_DOUBLE && ucv_type(uv2) == UC_DOUBLE &&
+ isnan(ucv_double_get(uv1)) && isnan(ucv_double_get(uv2)))
+ return true;
+
return ucv_is_equal(uv1, uv2);
}
diff --git a/tests/custom/04_bugs/30_nan_strict_equality b/tests/custom/04_bugs/30_nan_strict_equality
new file mode 100644
index 0000000..4ec32e2
--- /dev/null
+++ b/tests/custom/04_bugs/30_nan_strict_equality
@@ -0,0 +1,14 @@
+When comparing `nan` with `nan` for strict equality or inequality, the
+VM incorrectly treated the result as `true` or `false` respectively.
+
+-- Testcase --
+{{ NaN === NaN }}
+{{ NaN !== NaN }}
+{{ uniq([NaN, NaN]) }}
+-- End --
+
+-- Expect stdout --
+false
+true
+[ "NaN" ]
+-- End --
diff --git a/types.c b/types.c
index 5ea1180..dac0efb 100644
--- a/types.c
+++ b/types.c
@@ -1764,7 +1764,7 @@ ucv_is_equal(uc_value_t *uv1, uc_value_t *uv2)
if (t1 != t2)
return false;
- if (uv1 == uv2)
+ if (t1 != UC_DOUBLE && uv1 == uv2)
return true;
switch (t1) {