{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/4781","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/4781/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/4781/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/4781/events","html_url":"https://github.com/dotnet/roslyn/issues/4781","id":103087586,"number":4781,"title":"Discussion: Scope of pattern variables, and tuple decomposition","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-Language%20Design","name":"Area-Language Design","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Discussion","name":"Discussion","color":"fbca04"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Language-C%23","name":"Language-C#","color":"207de5"}],"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},"milestone":{"url":"https://api.github.com/repos/dotnet/roslyn/milestones/8","html_url":"https://github.com/dotnet/roslyn/milestones/C%23%207%20and%20VB%2015","labels_url":"https://api.github.com/repos/dotnet/roslyn/milestones/8/labels","id":962632,"number":8,"title":"C# 7 and VB 15","description":"\r\n\r\n<!---\r\n@huboard:{\"order\":0.375}\r\n-->\r\n","creator":{"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},"open_issues":45,"closed_issues":4,"state":"open","created_at":"2015-02-02T23:41:34Z","updated_at":"2015-08-26T19:17:14Z","due_on":null,"closed_at":null},"comments":47,"created_at":"2015-08-25T18:27:28Z","updated_at":"2015-08-27T12:34:03Z","closed_at":null,"body":"I’m doing a draft reimplementation of pattern matching (#206) now, and trying to figure out the right scoping of pattern variables. I had expected to use whatever we came up with for declaration expressions when those were under development, but it turns out that doesn’t make sense in many situations. For example, given the statement\r\n\r\n```cs\r\nM(x is int i ? i : 12);\r\n```\r\n\r\nThere is no point in the variable `i` being in scope outside this statement, as it won’t be *definitely assigned* anywhere else. My current thinking is that a pattern variable introduced in an expression would be limited in scope to the nearest enclosing statement, with the single exception that a pattern variable introduced in the condition of an `if` statement would not be in scope in the `else` clause.\r\n\r\nFor a field initializer, the scope would be limited to that declaration. For an expression-bodied property or method, limited to that declaration. For a ctor-initializer, limited to that ctor-initializer. The scope of a pattern variable introduced in a catch clause is the catch block.\r\n\r\nFor decomposing a tuple, I anticipate introducing a separate statement form, something like\r\n\r\n```cs\r\npattern := expression ;\r\n```\r\n\r\nFor example\r\n\r\n```cs\r\nvar tuple = (12, \"foo\");\r\n(int x, string y) := tuple;\r\n```\r\n\r\nThis has the same semantics as the expression\r\n\r\n```cs\r\nexpression is pattern\r\n```\r\n\r\nWith the exceptions that\r\n- It is a statement form, not an expression form;\r\n- The compiler must be able to prove that the match always succeeds (otherwise it is a compile-time error); and\r\n- Variables introduced in the pattern remain in scope within the enclosing block\r\n\r\nI welcome feedback and comments on this while is it fresh on the drawing board.\r\n@MadsTorgersen @ljw1004 @semihokur @AnthonyDGreen @terrajobst @jaredpar @Pilchie @mattwar @stephentoub @vancem "},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/135408056","html_url":"https://github.com/dotnet/roslyn/issues/4781#issuecomment-135408056","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/4781","id":135408056,"user":{"login":"HaloFour","id":10102290,"avatar_url":"https://avatars.githubusercontent.com/u/10102290?v=3","gravatar_id":"","url":"https://api.github.com/users/HaloFour","html_url":"https://github.com/HaloFour","followers_url":"https://api.github.com/users/HaloFour/followers","following_url":"https://api.github.com/users/HaloFour/following{/other_user}","gists_url":"https://api.github.com/users/HaloFour/gists{/gist_id}","starred_url":"https://api.github.com/users/HaloFour/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HaloFour/subscriptions","organizations_url":"https://api.github.com/users/HaloFour/orgs","repos_url":"https://api.github.com/users/HaloFour/repos","events_url":"https://api.github.com/users/HaloFour/events{/privacy}","received_events_url":"https://api.github.com/users/HaloFour/received_events","type":"User","site_admin":false},"created_at":"2015-08-27T12:34:02Z","updated_at":"2015-08-27T12:34:02Z","body":"@orthoxerox That's right, there are different boxing/unboxing rules for `Nullable<T>`.  Either way, the important bit of this conversation is regarding the scope of those parameters, not necessarily which pattern is being matched.  Type checking is just a simple pattern."}}