{"action":"created","issue":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/3096","labels_url":"https://api.github.com/repos/nim-lang/Nim/issues/3096/labels{/name}","comments_url":"https://api.github.com/repos/nim-lang/Nim/issues/3096/comments","events_url":"https://api.github.com/repos/nim-lang/Nim/issues/3096/events","html_url":"https://github.com/nim-lang/Nim/issues/3096","id":94169861,"number":3096,"title":"Incorrect code generated for tagged unions with enums not starting at zero","user":{"login":"zielmicha","id":364357,"avatar_url":"https://avatars.githubusercontent.com/u/364357?v=3","gravatar_id":"","url":"https://api.github.com/users/zielmicha","html_url":"https://github.com/zielmicha","followers_url":"https://api.github.com/users/zielmicha/followers","following_url":"https://api.github.com/users/zielmicha/following{/other_user}","gists_url":"https://api.github.com/users/zielmicha/gists{/gist_id}","starred_url":"https://api.github.com/users/zielmicha/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zielmicha/subscriptions","organizations_url":"https://api.github.com/users/zielmicha/orgs","repos_url":"https://api.github.com/users/zielmicha/repos","events_url":"https://api.github.com/users/zielmicha/events{/privacy}","received_events_url":"https://api.github.com/users/zielmicha/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/nim-lang/Nim/labels/High%20Priority","name":"High Priority","color":"e30c0c"},{"url":"https://api.github.com/repos/nim-lang/Nim/labels/Semcheck","name":"Semcheck","color":"d4c5f9"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-07-09T22:48:58Z","updated_at":"2015-09-21T06:14:42Z","closed_at":"2015-08-09T23:02:38Z","body":"```\r\ntype DbusTypeChar* = enum\r\n  dtArray = 'a',\r\n  dtDict = '{'\r\n\r\ntype DbusFoobar = ref object\r\n  case kind: DbusTypeChar:\r\n  of dtDict:\r\n    foo: int\r\n  else:\r\n    bar: int\r\n\r\nvar foobar: DbusFoobar\r\nfoobar.kind = dtDict\r\n```\r\nIn this example, DbusTypeChar is non-ordinal, but the compiler generates incorrect code even when `dtDict = 'b'`.\r\nGenerated C code:\r\nhttps://gist.github.com/zielmicha/9a72ab049820a154d4e3\r\nNimDT is declared as having 28 elements (`'{' - 'a' == 26`):\r\n```\r\nTNimNode* NimDT_91012_kind[28];\r\n```\r\nAnd the compiler generates out of bounds accesses (`'{' == 123`)\r\n```\r\nNimDT_91012_kind[123] = &TMP137[4];\r\n```"},"comment":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/comments/141885225","html_url":"https://github.com/nim-lang/Nim/issues/3096#issuecomment-141885225","issue_url":"https://api.github.com/repos/nim-lang/Nim/issues/3096","id":141885225,"user":{"login":"ziotom78","id":377795,"avatar_url":"https://avatars.githubusercontent.com/u/377795?v=3","gravatar_id":"","url":"https://api.github.com/users/ziotom78","html_url":"https://github.com/ziotom78","followers_url":"https://api.github.com/users/ziotom78/followers","following_url":"https://api.github.com/users/ziotom78/following{/other_user}","gists_url":"https://api.github.com/users/ziotom78/gists{/gist_id}","starred_url":"https://api.github.com/users/ziotom78/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ziotom78/subscriptions","organizations_url":"https://api.github.com/users/ziotom78/orgs","repos_url":"https://api.github.com/users/ziotom78/repos","events_url":"https://api.github.com/users/ziotom78/events{/privacy}","received_events_url":"https://api.github.com/users/ziotom78/received_events","type":"User","site_admin":false},"created_at":"2015-09-21T06:14:42Z","updated_at":"2015-09-21T06:14:42Z","body":"With this change, the following code (scrapped from a project of mine) does no longer compile:\r\n\r\n`````nim\r\ntype\r\n    DataType* {. pure .} = enum\r\n        Char = 1, \r\n        Int8 = 2,\r\n        Int16 = 3, \r\n        Int32 = 4, \r\n        Int64 = 5, \r\n        Float32 = 6, \r\n        Float64 = 7\r\n\r\n    DataSeq* {. pure .} = object\r\n        case kind* : DataType\r\n        of DataType.Char: charSeq* : seq[char]\r\n        of DataType.Int8: int8Seq* : seq[int8]\r\n        of DataType.Int16: int16Seq* : seq[int16]\r\n        of DataType.Int32: int32Seq* : seq[int32]\r\n        of DataType.Int64: int64Seq* : seq[int64]\r\n        of DataType.Float32: float32Seq* : seq[float32]\r\n        of DataType.Float64: float64Seq* : seq[float64]\r\n\r\n        length* : int\r\n`````\r\n\r\nIt fails with the message:\r\n\r\n    test.nim(12, 9) Error: low(kind) must be 0 for discriminant\r\n\r\nIs 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."}}