{"action":"created","issue":{"url":"https://api.github.com/repos/codemix/flow-runtime/issues/67","repository_url":"https://api.github.com/repos/codemix/flow-runtime","labels_url":"https://api.github.com/repos/codemix/flow-runtime/issues/67/labels{/name}","comments_url":"https://api.github.com/repos/codemix/flow-runtime/issues/67/comments","events_url":"https://api.github.com/repos/codemix/flow-runtime/issues/67/events","html_url":"https://github.com/codemix/flow-runtime/issues/67","id":212247602,"number":67,"title":"False-negative type errors using async functions","user":{"login":"doctyper","id":6960,"avatar_url":"https://avatars3.githubusercontent.com/u/6960?v=3","gravatar_id":"","url":"https://api.github.com/users/doctyper","html_url":"https://github.com/doctyper","followers_url":"https://api.github.com/users/doctyper/followers","following_url":"https://api.github.com/users/doctyper/following{/other_user}","gists_url":"https://api.github.com/users/doctyper/gists{/gist_id}","starred_url":"https://api.github.com/users/doctyper/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/doctyper/subscriptions","organizations_url":"https://api.github.com/users/doctyper/orgs","repos_url":"https://api.github.com/users/doctyper/repos","events_url":"https://api.github.com/users/doctyper/events{/privacy}","received_events_url":"https://api.github.com/users/doctyper/received_events","type":"User","site_admin":false},"labels":[{"id":466508745,"url":"https://api.github.com/repos/codemix/flow-runtime/labels/bug","name":"bug","color":"ee0701","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-03-06T20:57:26Z","updated_at":"2017-03-06T23:13:58Z","closed_at":null,"body":"<!--\r\n  Thanks for using flow-runtime! To help us address your issue quickly please\r\n  provide as much information about the problem you're facing, or the feature you'd like adding.\r\n-->\r\n\r\nThis is a:\r\n\r\n - [x] Bug Report\r\n - [ ] Feature Request\r\n - [ ] Question\r\n - [ ] Other\r\n\r\nWhich concerns:\r\n\r\n - [x] flow-runtime\r\n - [x] babel-plugin-flow-runtime\r\n - [ ] flow-runtime-validators\r\n - [ ] flow-runtime-mobx\r\n - [ ] flow-config-parser\r\n - [ ] The documentation website\r\n\r\n---\r\n\r\n### What is the current behaviour?\r\n<!--\r\n  If this is a bug report or question, please include example code wherever possible.\r\n  If your code is private and you can't share it, please create a sanitized version\r\n  which reproduces the issue. You may find the online demo useful for this:\r\n  https://codemix.github.io/flow-runtime/#/try\r\n\r\n  NOTE: It is **extremely** difficult to fix bugs without examples!\r\n-->\r\n\r\nIt appears flow-runtime gets confused type checking async functions. The following gives me an error in https://codemix.github.io/flow-runtime/#/try (default options):\r\n\r\n```js\r\nconst bar = async ({\r\n    id\r\n}: {\r\n    id: string;\r\n}) => {\r\n    return await new Promise(resolve => setTimeout(() => resolve(id), 1000));\r\n};\r\n\r\nconst foo = (id: string) => {\r\n    return bar({\r\n        id\r\n    })\r\n  \t\t\t.then(id => console.log(id))\r\n        .catch((e: Error) => console.error(\"foo\", e));\r\n};\r\n\r\nfoo(\"testId\");\r\n```\r\n\r\nresults in:\r\n\r\n```shell\r\nfoo TypeError: arguments[0].id must be a string\r\n\r\nExpected: string\r\n\r\nActual: void\r\n\r\n\r\n    at _callee$ (eval at run (https://codemix.github.io/flow-runtime/static/js/main.1ab3461d.js:20454:17), <anonymous>:20:169)\r\n    at tryCatch (https://codemix.github.io/flow-runtime/static/js/main.1ab3461d.js:59153:41)\r\n    at Generator.invoke [as _invoke] (https://codemix.github.io/flow-runtime/static/js/main.1ab3461d.js:59444:23)\r\n    at Generator.prototype.(anonymous function) [as next] (https://codemix.github.io/flow-runtime/static/js/main.1ab3461d.js:59205:22)\r\n    at step (eval at run (https://codemix.github.io/flow-runtime/static/js/main.1ab3461d.js:20454:17), <anonymous>:11:191)\r\n    at eval (eval at run (https://codemix.github.io/flow-runtime/static/js/main.1ab3461d.js:20454:17), <anonymous>:11:437)\r\n    at eval (eval at run (https://codemix.github.io/flow-runtime/static/js/main.1ab3461d.js:20454:17), <anonymous>:11:99)\r\n    at bar (eval at run (https://codemix.github.io/flow-runtime/static/js/main.1ab3461d.js:20454:17), <anonymous>:41:21)\r\n    at foo (eval at run (https://codemix.github.io/flow-runtime/static/js/main.1ab3461d.js:20454:17), <anonymous>:52:12)\r\n    at eval (eval at run (https://codemix.github.io/flow-runtime/static/js/main.1ab3461d.js:20454:17), <anonymous>:65:1)\r\n```\r\n\r\nWhereas non-async functions behave as expected:\r\n\r\n```js\r\nconst bar = ({\r\n    id\r\n}: {\r\n    id: string;\r\n}) => {\r\n    return new Promise(resolve => setTimeout(() => resolve(id), 1000));\r\n};\r\n\r\nconst foo = (id: string) => {\r\n    return bar({\r\n        id\r\n    })\r\n  \t\t\t.then(id => console.log(id))\r\n        .catch((e: Error) => console.error(\"foo\", e));\r\n};\r\n\r\nfoo(\"testId\");\r\n```\r\n\r\nresults in:\r\n\r\n```\r\ntestId\r\n```\r\n\r\n---\r\n\r\n### What is the expected behaviour?\r\n<!--\r\n  Please describe what you'd expect to happen under these circumstances.\r\n  If you are describing a bug in the babel plugin, please indicate the output\r\n  you'd expect it to produce.\r\n-->\r\n\r\nIt should not display false-negative results.\r\n\r\n---\r\n\r\n### Which package versions are you using?\r\n<!--\r\n  If this is a bug, which version(s) of the affected package(s) are you using?\r\n  If you're describing a bug specific to an environment, like a certain browser\r\n  or node version, please include that information here too.\r\n-->\r\nNode 6.9.1\r\n\r\nflow-runtime@0.7.0\r\nbabel-plugin-flow-runtime@0.7.0"},"comment":{"url":"https://api.github.com/repos/codemix/flow-runtime/issues/comments/284565922","html_url":"https://github.com/codemix/flow-runtime/issues/67#issuecomment-284565922","issue_url":"https://api.github.com/repos/codemix/flow-runtime/issues/67","id":284565922,"user":{"login":"phpnode","id":363611,"avatar_url":"https://avatars1.githubusercontent.com/u/363611?v=3","gravatar_id":"","url":"https://api.github.com/users/phpnode","html_url":"https://github.com/phpnode","followers_url":"https://api.github.com/users/phpnode/followers","following_url":"https://api.github.com/users/phpnode/following{/other_user}","gists_url":"https://api.github.com/users/phpnode/gists{/gist_id}","starred_url":"https://api.github.com/users/phpnode/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/phpnode/subscriptions","organizations_url":"https://api.github.com/users/phpnode/orgs","repos_url":"https://api.github.com/users/phpnode/repos","events_url":"https://api.github.com/users/phpnode/events{/privacy}","received_events_url":"https://api.github.com/users/phpnode/received_events","type":"User","site_admin":false},"created_at":"2017-03-06T23:13:58Z","updated_at":"2017-03-06T23:13:58Z","body":"ok, this happens because the hack we use to maintain reference to `arguments` in an arrow function (which we need for destructuring but is not ordinarily allowed) is getting mangled by regenerator. Curiously though, the official babel hack for this using `arg._shadowedFunctionLiteral = path` does not appear to work - `arguments` gets hoisted up too high. \r\n\r\nTL;DR - To fix this we need to create temporary vars to hold arguments and roll the actual destructuring into the function body, which is really a bit of a pain.  "}}
{"actor":{"display_login":"phpnode"}}