{"action":"created","issue":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4663","repository_url":"https://api.github.com/repos/HaxeFoundation/haxe","labels_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4663/labels{/name}","comments_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4663/comments","events_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4663/events","html_url":"https://github.com/HaxeFoundation/haxe/issues/4663","id":118417224,"number":4663,"title":"[analyzer] weird/unneeded array wrapping for captured vars","user":{"login":"nadako","id":49749,"avatar_url":"https://avatars.githubusercontent.com/u/49749?v=3","gravatar_id":"","url":"https://api.github.com/users/nadako","html_url":"https://github.com/nadako","followers_url":"https://api.github.com/users/nadako/followers","following_url":"https://api.github.com/users/nadako/following{/other_user}","gists_url":"https://api.github.com/users/nadako/gists{/gist_id}","starred_url":"https://api.github.com/users/nadako/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/nadako/subscriptions","organizations_url":"https://api.github.com/users/nadako/orgs","repos_url":"https://api.github.com/users/nadako/repos","events_url":"https://api.github.com/users/nadako/events{/privacy}","received_events_url":"https://api.github.com/users/nadako/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/HaxeFoundation/haxe/labels/feature-analyzer","name":"feature-analyzer","color":"207de5"}],"state":"open","locked":false,"assignee":{"login":"Simn","id":634365,"avatar_url":"https://avatars.githubusercontent.com/u/634365?v=3","gravatar_id":"","url":"https://api.github.com/users/Simn","html_url":"https://github.com/Simn","followers_url":"https://api.github.com/users/Simn/followers","following_url":"https://api.github.com/users/Simn/following{/other_user}","gists_url":"https://api.github.com/users/Simn/gists{/gist_id}","starred_url":"https://api.github.com/users/Simn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simn/subscriptions","organizations_url":"https://api.github.com/users/Simn/orgs","repos_url":"https://api.github.com/users/Simn/repos","events_url":"https://api.github.com/users/Simn/events{/privacy}","received_events_url":"https://api.github.com/users/Simn/received_events","type":"User","site_admin":false},"milestone":null,"comments":3,"created_at":"2015-11-23T16:22:52Z","updated_at":"2016-02-21T12:01:53Z","closed_at":null,"body":"```haxe\r\nclass Main {\r\n    static function main() {\r\n        function g(p) trace(p);\r\n        for (i in 0...3)\r\n            g.bind(i);\r\n    }\r\n}\r\n```\r\ngenerates WITH `-D analyzer` (note `f` and `p1` being wrapped)\r\n```js\r\nMain.main = function() {\r\n\tvar g = function(p) {\r\n\t\tconsole.log(p);\r\n\t};\r\n\tvar _g = 0;\r\n\twhile(_g < 3) {\r\n\t\tvar i = _g++;\r\n\t\tvar f = [g];\r\n\t\tvar p1 = [i];\r\n\t\t(function(p2,f1) {\r\n\t\t\treturn function() {\r\n\t\t\t\tf1[0](p2[0]);\r\n\t\t\t};\r\n\t\t})(p1,f);\r\n\t}\r\n};\r\n```\r\nwhile WITHOUT `-D analyzer` it's slightly better:\r\n```js\r\nMain.main = function() {\r\n\tvar g = function(p) {\r\n\t\tconsole.log(p);\r\n\t};\r\n\tvar _g = 0;\r\n\twhile(_g < 3) {\r\n\t\tvar i = _g++;\r\n\t\t(function(f,p1) {\r\n\t\t\treturn function() {\r\n\t\t\t\tf(p1);\r\n\t\t\t};\r\n\t\t})(g,i);\r\n\t}\r\n};\r\n```\r\n"},"comment":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/comments/186810046","html_url":"https://github.com/HaxeFoundation/haxe/issues/4663#issuecomment-186810046","issue_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4663","id":186810046,"user":{"login":"Simn","id":634365,"avatar_url":"https://avatars.githubusercontent.com/u/634365?v=3","gravatar_id":"","url":"https://api.github.com/users/Simn","html_url":"https://github.com/Simn","followers_url":"https://api.github.com/users/Simn/followers","following_url":"https://api.github.com/users/Simn/following{/other_user}","gists_url":"https://api.github.com/users/Simn/gists{/gist_id}","starred_url":"https://api.github.com/users/Simn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Simn/subscriptions","organizations_url":"https://api.github.com/users/Simn/orgs","repos_url":"https://api.github.com/users/Simn/repos","events_url":"https://api.github.com/users/Simn/events{/privacy}","received_events_url":"https://api.github.com/users/Simn/received_events","type":"User","site_admin":false},"created_at":"2016-02-21T12:01:53Z","updated_at":"2016-02-21T12:01:53Z","body":"So here's what happens:\r\n\r\n* `type_bind` generates the double closure\r\n* the self-calling closure is inlined by `reduce_loop`\r\n* `captured_vars` adds it back\r\n\r\nThat's as far as I got, I'm not sure what to do with this right now."}}