summary refs log tree commit diff stats
path: root/tests/template
diff options
context:
space:
mode:
authorAraq <rumpf_a@web.de>2015-02-04 12:40:23 +0100
committerAraq <rumpf_a@web.de>2015-02-04 12:51:54 +0100
commitb5f1957588c37fc5cef6e26a708f643cc8d0fc70 (patch)
treea381f34795da04c54f4aafc2474dbf392570a12b /tests/template
parent61e5f0dc51c42bd0a48db68bb5ba9f16e5d69404 (diff)
downloadNim-b5f1957588c37fc5cef6e26a708f643cc8d0fc70.tar.gz
fixes #2057
Diffstat (limited to 'tests/template')
-rw-r--r--tests/template/t2do.nim22
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/template/t2do.nim b/tests/template/t2do.nim
new file mode 100644
index 000000000..b87e3328c
--- /dev/null
+++ b/tests/template/t2do.nim
@@ -0,0 +1,22 @@
+discard """
+  output: "8.0"
+"""
+
+# bug #2057
+
+proc mpf_get_d(x: int): float = float(x)
+proc mpf_cmp_d(a: int; b: float): int = 0
+
+template toFloatHelper(result: expr; tooSmall, tooLarge: stmt) {.immediate.} =
+  result = mpf_get_d(a)
+  if result == 0.0 and mpf_cmp_d(a,0.0) != 0:
+    tooSmall
+  if result == Inf:
+    tooLarge
+
+proc toFloat*(a: int): float =
+  toFloatHelper(result)
+    do: raise newException(ValueError, "number too small"):
+        raise newException(ValueError, "number too large")
+
+echo toFloat(8)