{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/14651","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/14651/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/14651/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/14651/events","html_url":"https://github.com/dotnet/roslyn/issues/14651","id":184335508,"number":14651,"title":"Definite assignment versus pattern-matching when pattern always matches","user":{"login":"gafter","id":3804346,"avatar_url":"https://avatars.githubusercontent.com/u/3804346?v=3","gravatar_id":"","url":"https://api.github.com/users/gafter","html_url":"https://github.com/gafter","followers_url":"https://api.github.com/users/gafter/followers","following_url":"https://api.github.com/users/gafter/following{/other_user}","gists_url":"https://api.github.com/users/gafter/gists{/gist_id}","starred_url":"https://api.github.com/users/gafter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gafter/subscriptions","organizations_url":"https://api.github.com/users/gafter/orgs","repos_url":"https://api.github.com/users/gafter/repos","events_url":"https://api.github.com/users/gafter/events{/privacy}","received_events_url":"https://api.github.com/users/gafter/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Compilers","name":"Area-Compilers","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Language%20Design","name":"Area-Language Design","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Feature%20Request","name":"Feature Request","color":"fc2929"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Language-C%23","name":"Language-C#","color":"207de5"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/New%20Language%20Feature%20-%20Pattern%20Matching","name":"New Language Feature - Pattern Matching","color":"bfd4f2"}],"state":"open","locked":false,"assignee":{"login":"gafter","id":3804346,"avatar_url":"https://avatars.githubusercontent.com/u/3804346?v=3","gravatar_id":"","url":"https://api.github.com/users/gafter","html_url":"https://github.com/gafter","followers_url":"https://api.github.com/users/gafter/followers","following_url":"https://api.github.com/users/gafter/following{/other_user}","gists_url":"https://api.github.com/users/gafter/gists{/gist_id}","starred_url":"https://api.github.com/users/gafter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gafter/subscriptions","organizations_url":"https://api.github.com/users/gafter/orgs","repos_url":"https://api.github.com/users/gafter/repos","events_url":"https://api.github.com/users/gafter/events{/privacy}","received_events_url":"https://api.github.com/users/gafter/received_events","type":"User","site_admin":false},"assignees":[{"login":"gafter","id":3804346,"avatar_url":"https://avatars.githubusercontent.com/u/3804346?v=3","gravatar_id":"","url":"https://api.github.com/users/gafter","html_url":"https://github.com/gafter","followers_url":"https://api.github.com/users/gafter/followers","following_url":"https://api.github.com/users/gafter/following{/other_user}","gists_url":"https://api.github.com/users/gafter/gists{/gist_id}","starred_url":"https://api.github.com/users/gafter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gafter/subscriptions","organizations_url":"https://api.github.com/users/gafter/orgs","repos_url":"https://api.github.com/users/gafter/repos","events_url":"https://api.github.com/users/gafter/events{/privacy}","received_events_url":"https://api.github.com/users/gafter/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/dotnet/roslyn/milestones/16","html_url":"https://github.com/dotnet/roslyn/milestones/2.0%20(RTM)","labels_url":"https://api.github.com/repos/dotnet/roslyn/milestones/16/labels","id":1571384,"number":16,"title":"2.0 (RTM)","description":"","creator":{"login":"davkean","id":1103906,"avatar_url":"https://avatars.githubusercontent.com/u/1103906?v=3","gravatar_id":"","url":"https://api.github.com/users/davkean","html_url":"https://github.com/davkean","followers_url":"https://api.github.com/users/davkean/followers","following_url":"https://api.github.com/users/davkean/following{/other_user}","gists_url":"https://api.github.com/users/davkean/gists{/gist_id}","starred_url":"https://api.github.com/users/davkean/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/davkean/subscriptions","organizations_url":"https://api.github.com/users/davkean/orgs","repos_url":"https://api.github.com/users/davkean/repos","events_url":"https://api.github.com/users/davkean/events{/privacy}","received_events_url":"https://api.github.com/users/davkean/received_events","type":"User","site_admin":false},"open_issues":356,"closed_issues":90,"state":"open","created_at":"2016-02-08T21:54:04Z","updated_at":"2016-10-21T07:05:07Z","due_on":null,"closed_at":null},"comments":5,"created_at":"2016-10-20T20:42:44Z","updated_at":"2016-10-21T16:03:14Z","closed_at":null,"body":"This issue arises from a [recent question](https://github.com/dotnet/roslyn/issues/10153#issuecomment-255041399) by @uTeisT on pattern-matching.\r\n\r\nConsider a pattern-matching operation that always succeeds:\r\n```cs\r\n    void TestFunc(int i)\r\n    {\r\n        if (i is int j) { }\r\n        Console.WriteLine(j);\r\n    }\r\n```\r\nThis results in a definite assignment error on the use of j. That is because the current spec says that pattern variables are _definitely assigned when true_ for the pattern-matching operation. The implication is that they are not _definitely assigned_ when then pattern match fails (even though that cannot happen here), and so they are not definitely assigned after the if statement.\r\n\r\nWe could modify the specification so that a pattern-matching operation that always succeeds results in the pattern variables being definitely assigned. That is, a pattern-matching operation that is *irrefutable* (i.e. known to always succeed) would cause all variables to be *definitely assigned when false*.\r\n\r\nThat would allow this code to compile without error.\r\n\r\nNote that the converse situation, a pattern-matching operation that cannot succeed (because, for example, of a type mismatch), is a compile-time error, so no special definite assignment rule is required.\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/255417141","html_url":"https://github.com/dotnet/roslyn/issues/14651#issuecomment-255417141","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/14651","id":255417141,"user":{"login":"gafter","id":3804346,"avatar_url":"https://avatars.githubusercontent.com/u/3804346?v=3","gravatar_id":"","url":"https://api.github.com/users/gafter","html_url":"https://github.com/gafter","followers_url":"https://api.github.com/users/gafter/followers","following_url":"https://api.github.com/users/gafter/following{/other_user}","gists_url":"https://api.github.com/users/gafter/gists{/gist_id}","starred_url":"https://api.github.com/users/gafter/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/gafter/subscriptions","organizations_url":"https://api.github.com/users/gafter/orgs","repos_url":"https://api.github.com/users/gafter/repos","events_url":"https://api.github.com/users/gafter/events{/privacy}","received_events_url":"https://api.github.com/users/gafter/received_events","type":"User","site_admin":false},"created_at":"2016-10-21T16:03:14Z","updated_at":"2016-10-21T16:03:14Z","body":"@DavidArno This isn't a \"problem\", it is a place where the behavior has to be specified. The same \"problem\" exists no matter what the scope, due to operators such as `&&` and `||`."}}
{"actor":{"display_login":"gafter"}}