{"action":"created","issue":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/26948","repository_url":"https://api.github.com/repos/dart-lang/sdk","labels_url":"https://api.github.com/repos/dart-lang/sdk/issues/26948/labels{/name}","comments_url":"https://api.github.com/repos/dart-lang/sdk/issues/26948/comments","events_url":"https://api.github.com/repos/dart-lang/sdk/issues/26948/events","html_url":"https://github.com/dart-lang/sdk/issues/26948","id":167143248,"number":26948,"title":"Wrong context for closure in finally with await in try.","user":{"login":"zanderso","id":6343103,"avatar_url":"https://avatars.githubusercontent.com/u/6343103?v=3","gravatar_id":"","url":"https://api.github.com/users/zanderso","html_url":"https://github.com/zanderso","followers_url":"https://api.github.com/users/zanderso/followers","following_url":"https://api.github.com/users/zanderso/following{/other_user}","gists_url":"https://api.github.com/users/zanderso/gists{/gist_id}","starred_url":"https://api.github.com/users/zanderso/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/zanderso/subscriptions","organizations_url":"https://api.github.com/users/zanderso/orgs","repos_url":"https://api.github.com/users/zanderso/repos","events_url":"https://api.github.com/users/zanderso/events{/privacy}","received_events_url":"https://api.github.com/users/zanderso/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dart-lang/sdk/labels/area-vm","name":"area-vm","color":"c7def8"},{"url":"https://api.github.com/repos/dart-lang/sdk/labels/Type:%20bug","name":"Type: bug","color":"ededed"}],"state":"open","locked":false,"assignee":{"login":"mhausner","id":8368434,"avatar_url":"https://avatars.githubusercontent.com/u/8368434?v=3","gravatar_id":"","url":"https://api.github.com/users/mhausner","html_url":"https://github.com/mhausner","followers_url":"https://api.github.com/users/mhausner/followers","following_url":"https://api.github.com/users/mhausner/following{/other_user}","gists_url":"https://api.github.com/users/mhausner/gists{/gist_id}","starred_url":"https://api.github.com/users/mhausner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhausner/subscriptions","organizations_url":"https://api.github.com/users/mhausner/orgs","repos_url":"https://api.github.com/users/mhausner/repos","events_url":"https://api.github.com/users/mhausner/events{/privacy}","received_events_url":"https://api.github.com/users/mhausner/received_events","type":"User","site_admin":false},"assignees":[{"login":"mhausner","id":8368434,"avatar_url":"https://avatars.githubusercontent.com/u/8368434?v=3","gravatar_id":"","url":"https://api.github.com/users/mhausner","html_url":"https://github.com/mhausner","followers_url":"https://api.github.com/users/mhausner/followers","following_url":"https://api.github.com/users/mhausner/following{/other_user}","gists_url":"https://api.github.com/users/mhausner/gists{/gist_id}","starred_url":"https://api.github.com/users/mhausner/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mhausner/subscriptions","organizations_url":"https://api.github.com/users/mhausner/orgs","repos_url":"https://api.github.com/users/mhausner/repos","events_url":"https://api.github.com/users/mhausner/events{/privacy}","received_events_url":"https://api.github.com/users/mhausner/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/dart-lang/sdk/milestones/40","html_url":"https://github.com/dart-lang/sdk/milestones/1.18","labels_url":"https://api.github.com/repos/dart-lang/sdk/milestones/40/labels","id":1783492,"number":40,"title":"1.18","description":null,"creator":{"login":"floitschG","id":8631949,"avatar_url":"https://avatars.githubusercontent.com/u/8631949?v=3","gravatar_id":"","url":"https://api.github.com/users/floitschG","html_url":"https://github.com/floitschG","followers_url":"https://api.github.com/users/floitschG/followers","following_url":"https://api.github.com/users/floitschG/following{/other_user}","gists_url":"https://api.github.com/users/floitschG/gists{/gist_id}","starred_url":"https://api.github.com/users/floitschG/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/floitschG/subscriptions","organizations_url":"https://api.github.com/users/floitschG/orgs","repos_url":"https://api.github.com/users/floitschG/repos","events_url":"https://api.github.com/users/floitschG/events{/privacy}","received_events_url":"https://api.github.com/users/floitschG/received_events","type":"User","site_admin":false},"open_issues":1,"closed_issues":15,"state":"open","created_at":"2016-05-23T19:29:04Z","updated_at":"2016-07-26T02:28:13Z","due_on":null,"closed_at":null},"comments":7,"created_at":"2016-07-22T22:19:25Z","updated_at":"2016-07-27T07:06:58Z","closed_at":null,"body":"The program below should print 5.0 forever. However, after `doSync` is optimized, the closure passed to `doPrint` apparently has the wrong context, and extracts a bogus value for `next`.\r\n\r\nInvoke with, e.g.:\r\n\r\n```\r\n./out/DebugX64/dart --optimization-counter-threshold=10 --no-background-compilation ../duration_test.dart\r\n```\r\n\r\nThe bug can be worked around by pulling out the `finally` block of `doSync` into its own function, wrapped in a `try` so that we don't try to inline it.\r\n\r\n```dart\r\nimport 'dart:async';\r\nimport 'dart:io';\r\n\r\nvoid doPrint(Function f) {\r\n  print(f());\r\n}\r\n\r\nfoo() {\r\n  try {\r\n    var next = 5.0;\r\n    doPrint(() {\r\n      if (next != 5.0) {\r\n        print(\"next was crazy!\");\r\n        exit(-1);\r\n      }\r\n      return next;\r\n    });\r\n  } finally {}\r\n}\r\n\r\nFuture doSync() async {\r\n   try {\r\n     await 123;\r\n  } finally {\r\n    var next = 5.0;\r\n    doPrint(() {\r\n      if (next != 5.0) {\r\n        print(\"next was crazy!\");\r\n        exit(-1);\r\n      }\r\n      return next;\r\n    });\r\n    //foo();\r\n  }\r\n}\r\n\r\nmain() async {\r\n  int seconds = 0;\r\n  while (true) {\r\n    await doSync();\r\n  }\r\n}\r\n```"},"comment":{"url":"https://api.github.com/repos/dart-lang/sdk/issues/comments/235504131","html_url":"https://github.com/dart-lang/sdk/issues/26948#issuecomment-235504131","issue_url":"https://api.github.com/repos/dart-lang/sdk/issues/26948","id":235504131,"user":{"login":"whesse","id":4905639,"avatar_url":"https://avatars.githubusercontent.com/u/4905639?v=3","gravatar_id":"","url":"https://api.github.com/users/whesse","html_url":"https://github.com/whesse","followers_url":"https://api.github.com/users/whesse/followers","following_url":"https://api.github.com/users/whesse/following{/other_user}","gists_url":"https://api.github.com/users/whesse/gists{/gist_id}","starred_url":"https://api.github.com/users/whesse/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/whesse/subscriptions","organizations_url":"https://api.github.com/users/whesse/orgs","repos_url":"https://api.github.com/users/whesse/repos","events_url":"https://api.github.com/users/whesse/events{/privacy}","received_events_url":"https://api.github.com/users/whesse/received_events","type":"User","site_admin":false},"created_at":"2016-07-27T07:06:58Z","updated_at":"2016-07-27T07:06:58Z","body":"Because this issue is already in earlier stable releases, and does not have an immediate fix, I am not considering it a blocker for 1.18, and removing the milestone.  Let me know if you disagree, or have a fix that should be put in a patch release."}}
{"actor":{"display_login":"whesse"}}