diff options
author | Araq <rumpf_a@web.de> | 2014-03-22 02:49:51 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-03-22 02:49:51 +0100 |
commit | a431207e528dd0d69026465ea1df27c4e37dee93 (patch) | |
tree | 5b4b5dc51a5b7117396c54bef2c12d8db34f04bd | |
parent | 28e375c4f689c07ca15ec46da8e1693490331820 (diff) | |
download | Nim-a431207e528dd0d69026465ea1df27c4e37dee93.tar.gz |
bugfix: reprEnum for enums with negative values
-rw-r--r-- | lib/system/repr.nim | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/lib/system/repr.nim b/lib/system/repr.nim index cd3f7c3f4..7c1a68bc7 100644 --- a/lib/system/repr.nim +++ b/lib/system/repr.nim @@ -59,7 +59,11 @@ proc reprChar(x: char): string {.compilerRtl.} = proc reprEnum(e: int, typ: PNimType): string {.compilerRtl.} = # we read an 'int' but this may have been too large, so mask the other bits: - let e = e and (1 shl (typ.size*8)-1) + let e = if typ.size == 1: e and 0xff + elif typ.size == 2: e and 0xffff + else: e + # XXX we need a proper narrowing based on signedness here + #e and ((1 shl (typ.size*8)) - 1) if ntfEnumHole notin typ.flags: if e <% typ.node.len: return $typ.node.sons[e].name |