{"action":"created","issue":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/5132","repository_url":"https://api.github.com/repos/nim-lang/Nim","labels_url":"https://api.github.com/repos/nim-lang/Nim/issues/5132/labels{/name}","comments_url":"https://api.github.com/repos/nim-lang/Nim/issues/5132/comments","events_url":"https://api.github.com/repos/nim-lang/Nim/issues/5132/events","html_url":"https://github.com/nim-lang/Nim/issues/5132","id":196516415,"number":5132,"title":"Codegen: Faulty code with global pragma and indirect overload based initialization ","user":{"login":"ReneSac","id":6010063,"avatar_url":"https://avatars.githubusercontent.com/u/6010063?v=3","gravatar_id":"","url":"https://api.github.com/users/ReneSac","html_url":"https://github.com/ReneSac","followers_url":"https://api.github.com/users/ReneSac/followers","following_url":"https://api.github.com/users/ReneSac/following{/other_user}","gists_url":"https://api.github.com/users/ReneSac/gists{/gist_id}","starred_url":"https://api.github.com/users/ReneSac/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ReneSac/subscriptions","organizations_url":"https://api.github.com/users/ReneSac/orgs","repos_url":"https://api.github.com/users/ReneSac/repos","events_url":"https://api.github.com/users/ReneSac/events{/privacy}","received_events_url":"https://api.github.com/users/ReneSac/received_events","type":"User","site_admin":false},"labels":[{"id":202793755,"url":"https://api.github.com/repos/nim-lang/Nim/labels/error%20messages","name":"error messages","color":"d4c5f9","default":false}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2016-12-19T20:45:29Z","updated_at":"2016-12-21T15:19:33Z","closed_at":null,"body":"Sorry for the horrible title, but I don't fully understand what went wrong.\r\n\r\n```Nim\r\nproc initX(it: float): int = 8\r\n\r\nproc main() =\r\n  var f: float\r\n  var x {.global.} = initX(f)\r\n  \r\nmain()\r\n```\r\ngives:\r\n```\r\nError: execution of an external compiler program 'gcc -c  -w  -I [redacted] -o /tmp/aporia/nimcache/a7.o /tmp/aporia/nimcache/a7.c' failed with exit code: 1\r\n/tmp/aporia/nimcache/a7.c: In function ‘NimMainModule’:\r\n/tmp/aporia/nimcache/a7.c:110:44: error: ‘f0’ undeclared (first use in this function)\r\n  x_98010_899815578 = initx_98003_899815578(f0);\r\n                                            ^\r\n/tmp/aporia/nimcache/a7.c:110:44: note: each undeclared identifier is reported only once for each function it appears in\r\n> Process terminated with exit code 256\r\n````\r\nI'm using overload to control my program flow and this function generates the above error. It also give the same error if I replace the `float` by `int` too. The following variations of the main functions are fine:\r\n\r\nW/o parameters\r\n```nim\r\nproc initX(): int = 8\r\n\r\nproc main() =\r\n  var f: float\r\n  var x {.global.} = initX()\r\n  \r\nmain()\r\n```\r\n\r\nW/o {.global.}\r\n```nim\r\nproc initX(it: float): int = 8\r\n\r\nproc main() =\r\n  var f: float\r\n  var x = initX(f)\r\n  \r\nmain()\r\n````\r\n"},"comment":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/comments/268548251","html_url":"https://github.com/nim-lang/Nim/issues/5132#issuecomment-268548251","issue_url":"https://api.github.com/repos/nim-lang/Nim/issues/5132","id":268548251,"user":{"login":"Araq","id":287816,"avatar_url":"https://avatars.githubusercontent.com/u/287816?v=3","gravatar_id":"","url":"https://api.github.com/users/Araq","html_url":"https://github.com/Araq","followers_url":"https://api.github.com/users/Araq/followers","following_url":"https://api.github.com/users/Araq/following{/other_user}","gists_url":"https://api.github.com/users/Araq/gists{/gist_id}","starred_url":"https://api.github.com/users/Araq/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Araq/subscriptions","organizations_url":"https://api.github.com/users/Araq/orgs","repos_url":"https://api.github.com/users/Araq/repos","events_url":"https://api.github.com/users/Araq/events{/privacy}","received_events_url":"https://api.github.com/users/Araq/received_events","type":"User","site_admin":false},"created_at":"2016-12-21T15:19:33Z","updated_at":"2016-12-21T15:19:33Z","body":">  In the manual it says that \"When used within a generic proc, a separate unique global variable will be created for each instantiation of the proc.\"\r\n\r\nBut there is no generic involved.\r\n\r\n> And here a functionally equivalent version that works (and actually may be the perfect workaround for now):\r\n\r\nIt might be equivalent for your use case, but it's completely different from my perspective: It doesn't depend on a runtime value (ignored in the proc body or not doesn't matter).\r\n\r\n> While w/o the {.global.} that overloading works.\r\n\r\nCome on, that's not why it works and you know it. ``[int]``  is not the same as ``[T: int]``, you gave the generic type parameter the name ``int``, no specialization going on here.\r\n"}}
{"actor":{"display_login":"Araq"}}