summary refs log tree commit diff stats
diff options
context:
space:
mode:
-rw-r--r--compiler/semstmts.nim10
-rw-r--r--tests/vm/tconst_float_as_int.nim3
2 files changed, 11 insertions, 2 deletions
diff --git a/compiler/semstmts.nim b/compiler/semstmts.nim
index 5d1770a32..5f9989ea2 100644
--- a/compiler/semstmts.nim
+++ b/compiler/semstmts.nim
@@ -304,8 +304,14 @@ proc semTry(c: PContext, n: PNode): PNode =
 proc fitRemoveHiddenConv(c: PContext, typ: PType, n: PNode): PNode =
   result = fitNode(c, typ, n)
   if result.kind in {nkHiddenStdConv, nkHiddenSubConv}:
-    changeType(result.sons[1], typ, check=true)
-    result = result.sons[1]
+    let r1 = result.sons[1]
+    if r1.kind in {nkCharLit..nkUInt64Lit} and typ.skipTypes(abstractRange).kind in {tyFloat..tyFloat128}:
+      result = newFloatNode(nkFloatLit, BiggestFloat r1.intVal)
+      result.info = n.info
+      result.typ = typ
+    else:
+      changeType(r1, typ, check=true)
+      result = r1
   elif not sameType(result.typ, typ):
     changeType(result, typ, check=false)
 
diff --git a/tests/vm/tconst_float_as_int.nim b/tests/vm/tconst_float_as_int.nim
new file mode 100644
index 000000000..ed84ec194
--- /dev/null
+++ b/tests/vm/tconst_float_as_int.nim
@@ -0,0 +1,3 @@
+
+# bug #4619
+const x: float = 0