{"action":"created","issue":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4808","labels_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4808/labels{/name}","comments_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4808/comments","events_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4808/events","html_url":"https://github.com/HaxeFoundation/haxe/issues/4808","id":128390047,"number":4808,"title":"[js] js.Promise mixes up resolve and reject under certain circumstances","user":{"login":"Drakim","id":7129377,"avatar_url":"https://avatars.githubusercontent.com/u/7129377?v=3","gravatar_id":"","url":"https://api.github.com/users/Drakim","html_url":"https://github.com/Drakim","followers_url":"https://api.github.com/users/Drakim/followers","following_url":"https://api.github.com/users/Drakim/following{/other_user}","gists_url":"https://api.github.com/users/Drakim/gists{/gist_id}","starred_url":"https://api.github.com/users/Drakim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Drakim/subscriptions","organizations_url":"https://api.github.com/users/Drakim/orgs","repos_url":"https://api.github.com/users/Drakim/repos","events_url":"https://api.github.com/users/Drakim/events{/privacy}","received_events_url":"https://api.github.com/users/Drakim/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-24T11:31:43Z","updated_at":"2016-01-24T11:55:04Z","closed_at":null,"body":"```haxe\r\nimport js.Promise;\r\n\r\nclass Main {\r\n    static function main():Void {\r\n        new A().bar(function(test:{hello:String}) {\r\n\r\n        });\r\n    }\r\n}\r\n\r\nclass A {\r\n    public function new() {}\r\n    public function bar(_callback:{hello:String}->Void) {\r\n        Promise.all([\r\n            new Promise(function(resolve, reject) {resolve('test');}),\r\n            new Promise(function(resolve, reject) {resolve('test');})\r\n        ])\r\n        .then(function(result) {\r\n            //if(false) {_callback({hello: result[0]});}\r\n        });\r\n    }\r\n}\r\n```\r\nWhen compiled, the output's line 15 will be like this:\r\n`})]).then(function(result) {`\r\n\r\nBut if you uncomment my if(false) statement, output's line 15 will be like this:\r\n`})]).then(null,function(result) {`\r\n\r\nAs you can see, a null sneaked in there and made our anonymous function into the rejection callback of our Promise.all, which isn't what we want. It's extra bizzare since the if(false) statement isn't actually included in the final code, the compiler strips it away since it never triggers, meaning that extra null is the **only** difference.\r\n\r\nTested with version 3.2.1, and compiled with \"-main Main -js code.js\"\r\n"},"comment":{"url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/comments/174288570","html_url":"https://github.com/HaxeFoundation/haxe/issues/4808#issuecomment-174288570","issue_url":"https://api.github.com/repos/HaxeFoundation/haxe/issues/4808","id":174288570,"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},"created_at":"2016-01-24T11:55:04Z","updated_at":"2016-01-24T11:55:04Z","body":"@fponticelli could you look into it? the typing there looks pretty complicated..."}}