{"action":"created","issue":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/5926","repository_url":"https://api.github.com/repos/nim-lang/Nim","labels_url":"https://api.github.com/repos/nim-lang/Nim/issues/5926/labels{/name}","comments_url":"https://api.github.com/repos/nim-lang/Nim/issues/5926/comments","events_url":"https://api.github.com/repos/nim-lang/Nim/issues/5926/events","html_url":"https://github.com/nim-lang/Nim/issues/5926","id":232766892,"node_id":"MDU6SXNzdWUyMzI3NjY4OTI=","number":5926,"title":"\"Cannot instantiate\" error when template uses generic type","user":{"login":"endragor","id":2417849,"node_id":"MDQ6VXNlcjI0MTc4NDk=","avatar_url":"https://avatars2.githubusercontent.com/u/2417849?v=4","gravatar_id":"","url":"https://api.github.com/users/endragor","html_url":"https://github.com/endragor","followers_url":"https://api.github.com/users/endragor/followers","following_url":"https://api.github.com/users/endragor/following{/other_user}","gists_url":"https://api.github.com/users/endragor/gists{/gist_id}","starred_url":"https://api.github.com/users/endragor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/endragor/subscriptions","organizations_url":"https://api.github.com/users/endragor/orgs","repos_url":"https://api.github.com/users/endragor/repos","events_url":"https://api.github.com/users/endragor/events{/privacy}","received_events_url":"https://api.github.com/users/endragor/received_events","type":"User","site_admin":false},"labels":[{"id":121922867,"node_id":"MDU6TGFiZWwxMjE5MjI4Njc=","url":"https://api.github.com/repos/nim-lang/Nim/labels/Generics","name":"Generics","color":"fef2c0","default":false},{"id":431542100,"node_id":"MDU6TGFiZWw0MzE1NDIxMDA=","url":"https://api.github.com/repos/nim-lang/Nim/labels/Templates","name":"Templates","color":"c9d615","default":false}],"state":"open","locked":false,"assignee":{"login":"zah","id":175462,"node_id":"MDQ6VXNlcjE3NTQ2Mg==","avatar_url":"https://avatars2.githubusercontent.com/u/175462?v=4","gravatar_id":"","url":"https://api.github.com/users/zah","html_url":"https://github.com/zah","followers_url":"https://api.github.com/users/zah/followers","following_url":"https://api.github.com/users/zah/following{/other_user}","gists_url":"https://api.github.com/users/zah/gists{/gist_id}","starred_url":"https://api.github.com/users/zah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zah/subscriptions","organizations_url":"https://api.github.com/users/zah/orgs","repos_url":"https://api.github.com/users/zah/repos","events_url":"https://api.github.com/users/zah/events{/privacy}","received_events_url":"https://api.github.com/users/zah/received_events","type":"User","site_admin":false},"assignees":[{"login":"zah","id":175462,"node_id":"MDQ6VXNlcjE3NTQ2Mg==","avatar_url":"https://avatars2.githubusercontent.com/u/175462?v=4","gravatar_id":"","url":"https://api.github.com/users/zah","html_url":"https://github.com/zah","followers_url":"https://api.github.com/users/zah/followers","following_url":"https://api.github.com/users/zah/following{/other_user}","gists_url":"https://api.github.com/users/zah/gists{/gist_id}","starred_url":"https://api.github.com/users/zah/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zah/subscriptions","organizations_url":"https://api.github.com/users/zah/orgs","repos_url":"https://api.github.com/users/zah/repos","events_url":"https://api.github.com/users/zah/events{/privacy}","received_events_url":"https://api.github.com/users/zah/received_events","type":"User","site_admin":false}],"milestone":null,"comments":1,"created_at":"2017-06-01T05:05:21Z","updated_at":"2018-11-03T09:08:59Z","closed_at":null,"author_association":"CONTRIBUTOR","body":"Sample:\r\n```nim\r\ntype\r\n  SomeObj[T] = object\r\n\r\ntemplate useSomeObj[T]() =\r\n  var retObj: SomeObj[T]\r\n\r\nuseSomeObj[void]()\r\nuseSomeObj[int]()\r\n```\r\nOutput:\r\n```\r\nError: cannot instantiate SomeObj\r\ngot: (void)\r\nbut expected: (T)\r\n```\r\nThe error occurs both for `void` and `int`.\r\n\r\nGit hash: da52ade86e9df306b03958c5525a0e6973fc1cb5\r\n\r\n/cc @zah"},"comment":{"url":"https://api.github.com/repos/nim-lang/Nim/issues/comments/435572641","html_url":"https://github.com/nim-lang/Nim/issues/5926#issuecomment-435572641","issue_url":"https://api.github.com/repos/nim-lang/Nim/issues/5926","id":435572641,"node_id":"MDEyOklzc3VlQ29tbWVudDQzNTU3MjY0MQ==","user":{"login":"bluenote10","id":3620703,"node_id":"MDQ6VXNlcjM2MjA3MDM=","avatar_url":"https://avatars1.githubusercontent.com/u/3620703?v=4","gravatar_id":"","url":"https://api.github.com/users/bluenote10","html_url":"https://github.com/bluenote10","followers_url":"https://api.github.com/users/bluenote10/followers","following_url":"https://api.github.com/users/bluenote10/following{/other_user}","gists_url":"https://api.github.com/users/bluenote10/gists{/gist_id}","starred_url":"https://api.github.com/users/bluenote10/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/bluenote10/subscriptions","organizations_url":"https://api.github.com/users/bluenote10/orgs","repos_url":"https://api.github.com/users/bluenote10/repos","events_url":"https://api.github.com/users/bluenote10/events{/privacy}","received_events_url":"https://api.github.com/users/bluenote10/received_events","type":"User","site_admin":false},"created_at":"2018-11-03T09:08:59Z","updated_at":"2018-11-03T09:08:59Z","author_association":"CONTRIBUTOR","body":"I just ran into this issue as well. The problem still exists although there is a minor difference in the error reporting now. For me the problem seems to occur with any instantiation of `T` not just `int` and `void`:\r\n\r\n```nimrod\r\ntype\r\n  Data*[T] = object\r\n    x: T\r\n\r\ntemplate test*[T](xxx: T) =\r\n  let data = Data[T](x: xxx)\r\n\r\ntest(1)\r\n```\r\n\r\nTraceback:\r\n\r\n```\r\ntemplate_instantiation.nim(9, 5) template/generic instantiation of `test` from here\r\ntemplate_instantiation.nim(7, 18) Error: cannot instantiate Data\r\ngot: <int>\r\nbut expected: <T>\r\nTraceback (most recent call last)\r\nnim.nim(108)             nim\r\nnim.nim(72)              handleCmdLine\r\ncmdlinehelper.nim(91)    loadConfigsAndRunMainCommand\r\nmain.nim(163)            mainCommand\r\nmain.nim(74)             commandCompileToC\r\nmodules.nim(126)         compileProject\r\nmodules.nim(71)          compileModule\r\npasses.nim(194)          processModule\r\npasses.nim(86)           processTopLevelStmt\r\nsem.nim(600)             myProcess\r\nsem.nim(568)             semStmtAndGenerateGenerics\r\nsemstmts.nim(1973)       semStmt\r\nsemexprs.nim(913)        semExprNoType\r\nsemexprs.nim(2534)       semExpr\r\nsemstmts.nim(1914)       semStmtList\r\nsemexprs.nim(2427)       semExpr\r\nsemexprs.nim(895)        semDirectOp\r\nsemexprs.nim(789)        afterCallActions\r\nsemexprs.nim(31)         semTemplateExpr\r\nsem.nim(411)             semAfterMacroCall\r\nsemstmts.nim(1973)       semStmt\r\nsemexprs.nim(913)        semExprNoType\r\nsemexprs.nim(2534)       semExpr\r\nsemstmts.nim(1914)       semStmtList\r\nsemexprs.nim(2537)       semExpr\r\nsemstmts.nim(438)        semVarOrLet\r\nsemexprs.nim(59)         semExprWithType\r\nsemexprs.nim(2501)       semExpr\r\nsemobjconstr.nim(258)    semObjConstr\r\nsemtypes.nim(1458)       semTypeNode\r\nsemtypes.nim(1578)       semTypeNode\r\nsemtypes.nim(1246)       semGeneric\r\nmsgs.nim(519)            localError\r\nmsgs.nim(504)            liMessage\r\nmsgs.nim(332)            handleError\r\nmsgs.nim(317)            quit\r\n```\r\n\r\nI also found a work-around:\r\n\r\n```nimrod\r\ntemplate test*[T](xxx: T) =\r\n  type TT = T\r\n  let data = Data[TT](x: xxx)\r\n```"}}
{"actor":{"display_login":"bluenote10"}}