{"action":"created","comment":{"url":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/comments/35287741","id":35287741,"diff_hunk":"@@ -0,0 +1,20 @@\n+﻿using System.Compiler;\n+using System.Diagnostics.Contracts;\n+\n+namespace Microsoft.Contracts.Foxtrot.Utils\n+{\n+    internal static class TypeNodeExtensions\n+    {\n+        public static int TemplateArgumentsCount(this TypeNode typeNode)","path":"Foxtrot/Driver/Rewriting/Utils/TypeNodeExtensions.cs","position":8,"original_position":8,"commit_id":"9489878a5c6ad259ea8c88929c001d443347782d","original_commit_id":"9489878a5c6ad259ea8c88929c001d443347782d","user":{"login":"sharwell","id":1408396,"avatar_url":"https://avatars.githubusercontent.com/u/1408396?v=3","gravatar_id":"","url":"https://api.github.com/users/sharwell","html_url":"https://github.com/sharwell","followers_url":"https://api.github.com/users/sharwell/followers","following_url":"https://api.github.com/users/sharwell/following{/other_user}","gists_url":"https://api.github.com/users/sharwell/gists{/gist_id}","starred_url":"https://api.github.com/users/sharwell/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/sharwell/subscriptions","organizations_url":"https://api.github.com/users/sharwell/orgs","repos_url":"https://api.github.com/users/sharwell/repos","events_url":"https://api.github.com/users/sharwell/events{/privacy}","received_events_url":"https://api.github.com/users/sharwell/received_events","type":"User","site_admin":false},"body":":thought_balloon: I don't like this extension method for the same reason as `CountOrDefault`. The way to write this is the following:\r\n\r\n```\r\ntypeNode.TemplateArguments?.Count ?? 0;\r\n```","created_at":"2015-07-23T03:36:52Z","updated_at":"2015-07-23T03:36:52Z","html_url":"https://github.com/Microsoft/CodeContracts/pull/159#discussion_r35287741","pull_request_url":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/159","_links":{"self":{"href":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/comments/35287741"},"html":{"href":"https://github.com/Microsoft/CodeContracts/pull/159#discussion_r35287741"},"pull_request":{"href":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/159"}}},"pull_request":{"url":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/159","id":40323895,"html_url":"https://github.com/Microsoft/CodeContracts/pull/159","diff_url":"https://github.com/Microsoft/CodeContracts/pull/159.diff","patch_url":"https://github.com/Microsoft/CodeContracts/pull/159.patch","issue_url":"https://api.github.com/repos/Microsoft/CodeContracts/issues/159","number":159,"state":"open","locked":false,"title":"Reimplemented async closure generation","user":{"login":"SergeyTeplyakov","id":726448,"avatar_url":"https://avatars.githubusercontent.com/u/726448?v=3","gravatar_id":"","url":"https://api.github.com/users/SergeyTeplyakov","html_url":"https://github.com/SergeyTeplyakov","followers_url":"https://api.github.com/users/SergeyTeplyakov/followers","following_url":"https://api.github.com/users/SergeyTeplyakov/following{/other_user}","gists_url":"https://api.github.com/users/SergeyTeplyakov/gists{/gist_id}","starred_url":"https://api.github.com/users/SergeyTeplyakov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SergeyTeplyakov/subscriptions","organizations_url":"https://api.github.com/users/SergeyTeplyakov/orgs","repos_url":"https://api.github.com/users/SergeyTeplyakov/repos","events_url":"https://api.github.com/users/SergeyTeplyakov/events{/privacy}","received_events_url":"https://api.github.com/users/SergeyTeplyakov/received_events","type":"User","site_admin":false},"body":"This is a fist part of changes that addresses numerous issues related to async postconditions.\r\n\r\nThis PR addresses #155 and #156, but not #157 yet.\r\n\r\n# Rationale\r\n\r\nAs I mentioned in #155 and #156 current implementation of the async closure is not correct and changes behavior and semantic of the production code.\r\n\r\nNew approach is much more simple and does not changes behavior of the code.\r\n\r\n# New approach\r\n\r\n`EmitAsyncClosure` class generate `AsyncClosure` with `CheckMethod` and `CheckException` methods.\r\n\r\nFollowing transformation is applied to the original async method:\r\n\r\n```c#\r\n// This is original task, generated by the AsyncTaskMethodBuilder\r\nvar originalTask = t_builder.Task;\r\n\r\nvar closure = new AsyncClosure();\r\nvar task2 = originalTask.ContinueWith(closure.CheckPost).Unwrap();\r\nreturn task2;\r\n```\r\n\r\nTo use this approach `CheckPost` method's return type should be changed from `void`/`int` to `Task`/`Task<int>`.\r\n\r\nThere are 2 cases:\r\n\r\n1) Task has no return value. In this case only `EnsuresOnThrow` could be used, and we emit:\r\n\r\n```c#\r\nTask CheckMethod(Task t)\r\n{\r\n  if (t.Status == TaskStatus.Faulted)\r\n  {\r\n    // CheckException will throw if EnsuresOnThrow is not held\r\n    CheckException(t.Exception);\r\n  }\r\n\r\n  return t;\r\n}\r\n```\r\n\r\n2) Task(T) reutrns a T value. In this case both `EnsuresOnThrow` and `Contract.Ensures(Contract.Result)` could be used.\r\n\r\n```c#\r\nTask<int> CheckMethod(Task<int> t)\r\n{\r\n  if (t.Status == TaskStatus.Faulted)\r\n  {\r\n    // CheckException will throw if EnsuresOnThrow is not held\r\n    CheckException(t.Exception);\r\n  }\r\n  \r\n  if (t.Status == TaskStatus.RanToCompletion)\r\n  {\r\n     // Check ensures\r\n  }\r\n}\r\n```\r\n\r\nThis approach changes the behavior of the async method only when postcondition is violated but not changes the behavior otherwise.","created_at":"2015-07-20T05:10:54Z","updated_at":"2015-07-23T03:36:52Z","closed_at":null,"merged_at":null,"merge_commit_sha":"52156bfdf538552991df13e6307f88f3897a762b","assignee":null,"milestone":{"url":"https://api.github.com/repos/Microsoft/CodeContracts/milestones/2","html_url":"https://github.com/Microsoft/CodeContracts/milestones/Async%20Features","labels_url":"https://api.github.com/repos/Microsoft/CodeContracts/milestones/2/labels","id":1209830,"number":2,"title":"Async Features","description":"There is a plenty of issues in ccrewrite related to preconditions/postconditions in the async methods.\r\n\r\nThis milestone will help to keep track all of them.","creator":{"login":"SergeyTeplyakov","id":726448,"avatar_url":"https://avatars.githubusercontent.com/u/726448?v=3","gravatar_id":"","url":"https://api.github.com/users/SergeyTeplyakov","html_url":"https://github.com/SergeyTeplyakov","followers_url":"https://api.github.com/users/SergeyTeplyakov/followers","following_url":"https://api.github.com/users/SergeyTeplyakov/following{/other_user}","gists_url":"https://api.github.com/users/SergeyTeplyakov/gists{/gist_id}","starred_url":"https://api.github.com/users/SergeyTeplyakov/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/SergeyTeplyakov/subscriptions","organizations_url":"https://api.github.com/users/SergeyTeplyakov/orgs","repos_url":"https://api.github.com/users/SergeyTeplyakov/repos","events_url":"https://api.github.com/users/SergeyTeplyakov/events{/privacy}","received_events_url":"https://api.github.com/users/SergeyTeplyakov/received_events","type":"User","site_admin":false},"open_issues":4,"closed_issues":1,"state":"open","created_at":"2015-07-15T18:05:39Z","updated_at":"2015-07-20T05:10:54Z","due_on":null,"closed_at":null},"commits_url":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/159/commits","review_comments_url":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/159/comments","review_comment_url":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/comments{/number}","comments_url":"https://api.github.com/repos/Microsoft/CodeContracts/issues/159/comments","statuses_url":"https://api.github.com/repos/Microsoft/CodeContracts/statuses/9489878a5c6ad259ea8c88929c001d443347782d","head":{"label":"Microsoft:feature/ProperAsyncPost","ref":"feature/ProperAsyncPost","sha":"9489878a5c6ad259ea8c88929c001d443347782d","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":28880434,"name":"CodeContracts","full_name":"Microsoft/CodeContracts","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/CodeContracts","description":"Source code for the CodeContracts tools for .NET","fork":false,"url":"https://api.github.com/repos/Microsoft/CodeContracts","forks_url":"https://api.github.com/repos/Microsoft/CodeContracts/forks","keys_url":"https://api.github.com/repos/Microsoft/CodeContracts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/CodeContracts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/CodeContracts/teams","hooks_url":"https://api.github.com/repos/Microsoft/CodeContracts/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/CodeContracts/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/CodeContracts/events","assignees_url":"https://api.github.com/repos/Microsoft/CodeContracts/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/CodeContracts/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/CodeContracts/tags","blobs_url":"https://api.github.com/repos/Microsoft/CodeContracts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/CodeContracts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/CodeContracts/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/CodeContracts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/CodeContracts/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/CodeContracts/languages","stargazers_url":"https://api.github.com/repos/Microsoft/CodeContracts/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/CodeContracts/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/CodeContracts/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/CodeContracts/subscription","commits_url":"https://api.github.com/repos/Microsoft/CodeContracts/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/CodeContracts/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/CodeContracts/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/CodeContracts/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/CodeContracts/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/CodeContracts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/CodeContracts/merges","archive_url":"https://api.github.com/repos/Microsoft/CodeContracts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/CodeContracts/downloads","issues_url":"https://api.github.com/repos/Microsoft/CodeContracts/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/CodeContracts/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/CodeContracts/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/CodeContracts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/CodeContracts/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/CodeContracts/releases{/id}","created_at":"2015-01-06T19:48:32Z","updated_at":"2015-07-23T01:32:16Z","pushed_at":"2015-07-22T20:21:27Z","git_url":"git://github.com/Microsoft/CodeContracts.git","ssh_url":"git@github.com:Microsoft/CodeContracts.git","clone_url":"https://github.com/Microsoft/CodeContracts.git","svn_url":"https://github.com/Microsoft/CodeContracts","homepage":null,"size":270651,"stargazers_count":260,"watchers_count":260,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":42,"mirror_url":null,"open_issues_count":65,"forks":42,"open_issues":65,"watchers":260,"default_branch":"master"}},"base":{"label":"Microsoft:master","ref":"master","sha":"cfc6fb8dfe303e3d7ee403878e6be81ce03637ec","user":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"repo":{"id":28880434,"name":"CodeContracts","full_name":"Microsoft/CodeContracts","owner":{"login":"Microsoft","id":6154722,"avatar_url":"https://avatars.githubusercontent.com/u/6154722?v=3","gravatar_id":"","url":"https://api.github.com/users/Microsoft","html_url":"https://github.com/Microsoft","followers_url":"https://api.github.com/users/Microsoft/followers","following_url":"https://api.github.com/users/Microsoft/following{/other_user}","gists_url":"https://api.github.com/users/Microsoft/gists{/gist_id}","starred_url":"https://api.github.com/users/Microsoft/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Microsoft/subscriptions","organizations_url":"https://api.github.com/users/Microsoft/orgs","repos_url":"https://api.github.com/users/Microsoft/repos","events_url":"https://api.github.com/users/Microsoft/events{/privacy}","received_events_url":"https://api.github.com/users/Microsoft/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/Microsoft/CodeContracts","description":"Source code for the CodeContracts tools for .NET","fork":false,"url":"https://api.github.com/repos/Microsoft/CodeContracts","forks_url":"https://api.github.com/repos/Microsoft/CodeContracts/forks","keys_url":"https://api.github.com/repos/Microsoft/CodeContracts/keys{/key_id}","collaborators_url":"https://api.github.com/repos/Microsoft/CodeContracts/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/Microsoft/CodeContracts/teams","hooks_url":"https://api.github.com/repos/Microsoft/CodeContracts/hooks","issue_events_url":"https://api.github.com/repos/Microsoft/CodeContracts/issues/events{/number}","events_url":"https://api.github.com/repos/Microsoft/CodeContracts/events","assignees_url":"https://api.github.com/repos/Microsoft/CodeContracts/assignees{/user}","branches_url":"https://api.github.com/repos/Microsoft/CodeContracts/branches{/branch}","tags_url":"https://api.github.com/repos/Microsoft/CodeContracts/tags","blobs_url":"https://api.github.com/repos/Microsoft/CodeContracts/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/Microsoft/CodeContracts/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/Microsoft/CodeContracts/git/refs{/sha}","trees_url":"https://api.github.com/repos/Microsoft/CodeContracts/git/trees{/sha}","statuses_url":"https://api.github.com/repos/Microsoft/CodeContracts/statuses/{sha}","languages_url":"https://api.github.com/repos/Microsoft/CodeContracts/languages","stargazers_url":"https://api.github.com/repos/Microsoft/CodeContracts/stargazers","contributors_url":"https://api.github.com/repos/Microsoft/CodeContracts/contributors","subscribers_url":"https://api.github.com/repos/Microsoft/CodeContracts/subscribers","subscription_url":"https://api.github.com/repos/Microsoft/CodeContracts/subscription","commits_url":"https://api.github.com/repos/Microsoft/CodeContracts/commits{/sha}","git_commits_url":"https://api.github.com/repos/Microsoft/CodeContracts/git/commits{/sha}","comments_url":"https://api.github.com/repos/Microsoft/CodeContracts/comments{/number}","issue_comment_url":"https://api.github.com/repos/Microsoft/CodeContracts/issues/comments{/number}","contents_url":"https://api.github.com/repos/Microsoft/CodeContracts/contents/{+path}","compare_url":"https://api.github.com/repos/Microsoft/CodeContracts/compare/{base}...{head}","merges_url":"https://api.github.com/repos/Microsoft/CodeContracts/merges","archive_url":"https://api.github.com/repos/Microsoft/CodeContracts/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/Microsoft/CodeContracts/downloads","issues_url":"https://api.github.com/repos/Microsoft/CodeContracts/issues{/number}","pulls_url":"https://api.github.com/repos/Microsoft/CodeContracts/pulls{/number}","milestones_url":"https://api.github.com/repos/Microsoft/CodeContracts/milestones{/number}","notifications_url":"https://api.github.com/repos/Microsoft/CodeContracts/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/Microsoft/CodeContracts/labels{/name}","releases_url":"https://api.github.com/repos/Microsoft/CodeContracts/releases{/id}","created_at":"2015-01-06T19:48:32Z","updated_at":"2015-07-23T01:32:16Z","pushed_at":"2015-07-22T20:21:27Z","git_url":"git://github.com/Microsoft/CodeContracts.git","ssh_url":"git@github.com:Microsoft/CodeContracts.git","clone_url":"https://github.com/Microsoft/CodeContracts.git","svn_url":"https://github.com/Microsoft/CodeContracts","homepage":null,"size":270651,"stargazers_count":260,"watchers_count":260,"language":"C#","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":42,"mirror_url":null,"open_issues_count":65,"forks":42,"open_issues":65,"watchers":260,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/159"},"html":{"href":"https://github.com/Microsoft/CodeContracts/pull/159"},"issue":{"href":"https://api.github.com/repos/Microsoft/CodeContracts/issues/159"},"comments":{"href":"https://api.github.com/repos/Microsoft/CodeContracts/issues/159/comments"},"review_comments":{"href":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/159/comments"},"review_comment":{"href":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/Microsoft/CodeContracts/pulls/159/commits"},"statuses":{"href":"https://api.github.com/repos/Microsoft/CodeContracts/statuses/9489878a5c6ad259ea8c88929c001d443347782d"}}}}