浏览代码

[eval] make Std.parseInt return NaN on invalid input

closes #9904
Simon Krajewski 4 年之前
父节点
当前提交
395393eb7d
共有 2 个文件被更改,包括 9 次插入1 次删除
  1. 1 1
      src/macro/eval/evalStdLib.ml
  2. 8 0
      tests/unit/src/unit/issues/Issue9904.hx

+ 1 - 1
src/macro/eval/evalStdLib.ml

@@ -2171,7 +2171,7 @@ module StdStd = struct
 	)
 
 	let parseFloat = vfun1 (fun v ->
-		try vfloat (Numeric.parse_float (decode_string v)) with _ -> vnull
+		try vfloat (Numeric.parse_float (decode_string v)) with _ -> vfloat Float.nan
 	)
 
 	let random = vfun1 (fun v ->

+ 8 - 0
tests/unit/src/unit/issues/Issue9904.hx

@@ -0,0 +1,8 @@
+package unit.issues;
+
+class Issue9904 extends unit.Test {
+	function test() {
+		f(Std.parseFloat("a") == null);
+		t(Math.isNaN(Std.parseFloat("a")));
+	}
+}