{"action":"created","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/27768","repository_url":"https://api.github.com/repos/dart-lang/sdk","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/27768/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/27768/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/27768/events","html_url":"https://github.com/dart-lang/sdk/issues/27768","id":187476665,"number":27768,"title":"Analyzer FR: Detect when futures are not properly chained","user":{"login":"mehmetf","id":6687929,"avatar_url":"https://avatars.githubusercontent.com/u/6687929?v=3","gravatar_id":"","url":"https://api.github.com/users/mehmetf","html_url":"https://github.com/mehmetf","followers_url":"https://api.github.com/users/mehmetf/followers","following_url":"https://api.github.com/users/mehmetf/following{/other_user}","gists_url":"https://api.github.com/users/mehmetf/gists{/gist_id}","starred_url":"https://api.github.com/users/mehmetf/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mehmetf/subscriptions","organizations_url":"https://api.github.com/users/mehmetf/orgs","repos_url":"https://api.github.com/users/mehmetf/repos","events_url":"https://api.github.com/users/mehmetf/events{/privacy}","received_events_url":"https://api.github.com/users/mehmetf/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-11-05T04:46:18Z","updated_at":"2016-11-06T00:28:13Z","closed_at":"2016-11-05T21:31:40Z","body":"Consider the following innocent looking code:\r\n\r\n```Dart\r\nFuture<String> runSomeOp() {\r\n  return someOp().then((_) {\r\n    log(\"Finished!\");\r\n  });\r\n}\r\n\r\n// Much later in code\r\n\r\nvoid someMethod() {\r\n  runSomeOp().then((value) {\r\n    print('Happily use $value');\r\n  });\r\n}\r\n```\r\n\r\nThe intent here is to attach multiple callbacks to the same future, not to chain the futures. The correct code is one dot away:\r\n\r\n```Dart\r\nFuture<String> runSomeOp() {\r\n  return someOp()..then((_) {\r\n    log(\"Finished!\");\r\n  });\r\n}\r\n\r\n// Much later in code\r\n\r\nvoid someMethod() {\r\n  runSomeOp().then((value) {\r\n    print('Happily use $value');\r\n  });\r\n}\r\n```\r\n\r\nI was hoping Analyzer can catch cases like this because it knows the method is expected to return a Future<String> and the ```then``` block has no return statement."},"comment":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/comments/258651795","html_url":"https://github.com/dart-lang/sdk/issues/27768#issuecomment-258651795","issue_url":"https://api.github.com/repos/dart-lang/sdk/issues/27768","id":258651795,"user":{"login":"lrhn","id":4865287,"avatar_url":"https://avatars.githubusercontent.com/u/4865287?v=3","gravatar_id":"","url":"https://api.github.com/users/lrhn","html_url":"https://github.com/lrhn","followers_url":"https://api.github.com/users/lrhn/followers","following_url":"https://api.github.com/users/lrhn/following{/other_user}","gists_url":"https://api.github.com/users/lrhn/gists{/gist_id}","starred_url":"https://api.github.com/users/lrhn/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/lrhn/subscriptions","organizations_url":"https://api.github.com/users/lrhn/orgs","repos_url":"https://api.github.com/users/lrhn/repos","events_url":"https://api.github.com/users/lrhn/events{/privacy}","received_events_url":"https://api.github.com/users/lrhn/received_events","type":"User","site_admin":false},"created_at":"2016-11-06T00:28:13Z","updated_at":"2016-11-06T00:28:13Z","body":"The problem here is compounded by your function-without-a-return-statement because that still effectively returns `null` and `null` is assignable to `String`. That means that the program isn't doing anything visibly wrong."}}
{"actor":{"display_login":"lrhn"}}