diff options
author | Andreas Rumpf <rumpf_a@web.de> | 2016-08-23 01:10:34 +0200 |
---|---|---|
committer | Andreas Rumpf <rumpf_a@web.de> | 2016-08-23 01:10:34 +0200 |
commit | e9e413552af0480747d025d422a0ea9500c582a2 (patch) | |
tree | 0b6a80f129e6915e22f3f36c607fab5d9ba488bc | |
parent | 9c9a7b6520e45cc71f071e82e8306ad276d72258 (diff) | |
download | Nim-e9e413552af0480747d025d422a0ea9500c582a2.tar.gz |
fixes #4619
-rw-r--r-- | compiler/semstmts.nim | 10 | ||||
-rw-r--r-- | tests/vm/tconst_float_as_int.nim | 3 |
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 |