You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
type DbusTypeChar* = enum
dtArray = 'a',
dtDict = '{'
type DbusFoobar = ref object
case kind: DbusTypeChar:
of dtDict:
foo: int
else:
bar: int
var foobar: DbusFoobar
foobar.kind = dtDict
In this example, DbusTypeChar is non-ordinal, but the compiler generates incorrect code even when dtDict = 'b'.
Generated C code: https://gist.github.com/zielmicha/9a72ab049820a154d4e3
NimDT is declared as having 28 elements ('{' - 'a' == 26):
TNimNode* NimDT_91012_kind[28];
And the compiler generates out of bounds accesses ('{' == 123)
NimDT_91012_kind[123] = &TMP137[4];
The text was updated successfully, but these errors were encountered:
zielmicha
changed the title
Incorrect code generated for tagged unions with enums not starting with zero
Incorrect code generated for tagged unions with enums not starting at zero
Jul 9, 2015
When all enums start with zero, this change does nothing.
When first item of enum is bigger than zero, NimDT array size is
equal to last element index + 2, so no out-of-bounds accesses are
generated. TNimNode.len field is also changed.
test.nim(12, 9) Error: low(kind) must be 0 for discriminant
Is this intentional? I would prefer not to change the values in the DataType enum, as they match the numbers expected in a byte stream read by the program.
In this example, DbusTypeChar is non-ordinal, but the compiler generates incorrect code even when
dtDict = 'b'
.Generated C code:
https://gist.github.com/zielmicha/9a72ab049820a154d4e3
NimDT is declared as having 28 elements (
'{' - 'a' == 26
):And the compiler generates out of bounds accesses (
'{' == 123
)The text was updated successfully, but these errors were encountered: