{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/14862","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/14862/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/14862/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/14862/events","html_url":"https://github.com/dotnet/roslyn/issues/14862","id":186629856,"number":14862,"title":"Name Lookup for Wildcards","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":[{"id":169838071,"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Language%20Design","name":"Area-Language Design","color":"5319e7","default":false},{"id":166377946,"url":"https://api.github.com/repos/dotnet/roslyn/labels/Language-C%23","name":"Language-C#","color":"207de5","default":false},{"id":359270827,"url":"https://api.github.com/repos/dotnet/roslyn/labels/New%20Language%20Feature%20-%20Out%20Variable%20Declaration","name":"New Language Feature - Out Variable Declaration","color":"bfd4f2","default":false},{"id":326633537,"url":"https://api.github.com/repos/dotnet/roslyn/labels/New%20Language%20Feature%20-%20Pattern%20Matching","name":"New Language Feature - Pattern Matching","color":"bfd4f2","default":false},{"id":332342663,"url":"https://api.github.com/repos/dotnet/roslyn/labels/New%20Language%20Feature%20-%20Tuples","name":"New Language Feature - Tuples","color":"bfd4f2","default":false}],"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},{"login":"MadsTorgersen","id":6677272,"avatar_url":"https://avatars.githubusercontent.com/u/6677272?v=3","gravatar_id":"","url":"https://api.github.com/users/MadsTorgersen","html_url":"https://github.com/MadsTorgersen","followers_url":"https://api.github.com/users/MadsTorgersen/followers","following_url":"https://api.github.com/users/MadsTorgersen/following{/other_user}","gists_url":"https://api.github.com/users/MadsTorgersen/gists{/gist_id}","starred_url":"https://api.github.com/users/MadsTorgersen/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MadsTorgersen/subscriptions","organizations_url":"https://api.github.com/users/MadsTorgersen/orgs","repos_url":"https://api.github.com/users/MadsTorgersen/repos","events_url":"https://api.github.com/users/MadsTorgersen/events{/privacy}","received_events_url":"https://api.github.com/users/MadsTorgersen/received_events","type":"User","site_admin":false}],"milestone":{"url":"https://api.github.com/repos/dotnet/roslyn/milestones/24","html_url":"https://github.com/dotnet/roslyn/milestones/2.0%20(RC.2)","labels_url":"https://api.github.com/repos/dotnet/roslyn/milestones/24/labels","id":2090735,"number":24,"title":"2.0 (RC.2)","description":"","creator":{"login":"jaredpar","id":146967,"avatar_url":"https://avatars.githubusercontent.com/u/146967?v=3","gravatar_id":"","url":"https://api.github.com/users/jaredpar","html_url":"https://github.com/jaredpar","followers_url":"https://api.github.com/users/jaredpar/followers","following_url":"https://api.github.com/users/jaredpar/following{/other_user}","gists_url":"https://api.github.com/users/jaredpar/gists{/gist_id}","starred_url":"https://api.github.com/users/jaredpar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jaredpar/subscriptions","organizations_url":"https://api.github.com/users/jaredpar/orgs","repos_url":"https://api.github.com/users/jaredpar/repos","events_url":"https://api.github.com/users/jaredpar/events{/privacy}","received_events_url":"https://api.github.com/users/jaredpar/received_events","type":"User","site_admin":false},"open_issues":109,"closed_issues":11,"state":"open","created_at":"2016-10-24T21:54:24Z","updated_at":"2016-11-02T02:04:33Z","due_on":null,"closed_at":null},"comments":14,"created_at":"2016-11-01T19:53:54Z","updated_at":"2016-11-02T09:22:59Z","closed_at":null,"body":"We are considering a number of [small changes to deconstruction, out variables, and pattern-matching](https://github.com/dotnet/roslyn/issues/14794) to allow the use of *wildcards* where one could declare a variable, but the user has no intention of using the value captured in that variable. Here we discuss an open issue around name lookup, and propose a resolution.\r\n\r\nThe summary of this proposal is that the use of a wildcard has no effect on name lookup elsewhere in the code.\r\n\r\n### Original (LDM) approach\r\n\r\nThe original approach described by LDM was that the lookup of the identifier `_` would treat it as a wildcard if nothing were found:\r\n\r\n```cs\r\nclass Sample\r\n{\r\n    void M()\r\n    {\r\n        M2(out _); // ok wildcard\r\n    }\r\n}\r\n```\r\n\r\nmultiple declarations of the identifier `_` in the same scope would cause `_` to be considered a wildcard:\r\n\r\n```cs\r\nclass Sample\r\n{\r\n    void M()\r\n    {\r\n        int _ = e1;\r\n        int _ = e2;\r\n        M(out _); // ok, wildcard\r\n    }\r\n}\r\n```\r\n\r\nExisting cases, where the identifier is declared once, would still introduce a variable named `_`:\r\n\r\n```cs\r\nclass Sample\r\n{\r\n    void M(object o)\r\n    {\r\n        if (o is int _)\r\n        {\r\n            Console.WriteLine(_); //, uses declared pattern variable _\r\n        }\r\n    }\r\n}\r\n```\r\n\r\n### Criticism of the this approach\r\n\r\nThis approach treats an unbound identifier `_` as a wildcard, a single definition of `_` as causing `_` to bind to that definition, and multiple definitions again treating the use of `_` as a wildcard. It requires careful definition of what \"multiple definitions\" are. Would a declaration of `_` in an outer scope, and redeclaration in an inner scope cause a use to be a wildcard?\r\n\r\n```cs\r\nclass Sample\r\n{\r\n    void M(object o)\r\n    {\r\n        if (o is int _)\r\n        {\r\n            M(out int _); // allowed? wildcard?\r\n        }\r\n    }\r\n}\r\n```\r\n\r\nThere are corresponding implementation difficulties that may make this approach unattractive.\r\n\r\n### Proposed alternative\r\n\r\nThe proposed alternative is that \r\n- the *declaration* of an identifier `_` in the following contexts would always be treated as a wildcard, and would have no effect on name lookup elsewhere:\r\n  - an out argument,\r\n  - the left-hand-side of a deconstruction, or\r\n  - a pattern variable\r\n- the use of the simple identifier `_` as an expression as an out argument, or as a variable in the left-hand-side of a deconstruction, would be bound to a variable of that name. If no variable of that name is found, it is treated as a wildcard. This is similar to the treatment of `var` as a type.\r\n\r\n```cs\r\nclass Sample\r\n{\r\n    void M(object o)\r\n    {\r\n        if (o is int _) // wildcard by 1.\r\n        {\r\n            M(out int _); // wildcard by 1.\r\n        }\r\n        (int x, int _) = e; // wildcard by 1.\r\n\r\n        M(out _); // wildcard by 2.\r\n        (o, _) = e; // wildcard by 2.\r\n        (int x, _) = e; // wildcard by 2.\r\n\r\n        Console.WriteLine(_); // error: no _ in scope\r\n    }\r\n}\r\n```\r\n\r\nThis is much simpler to implement and I believe much easier to explain.\r\n"},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/257812347","html_url":"https://github.com/dotnet/roslyn/issues/14862#issuecomment-257812347","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/14862","id":257812347,"user":{"login":"CyrusNajmabadi","id":4564579,"avatar_url":"https://avatars.githubusercontent.com/u/4564579?v=3","gravatar_id":"","url":"https://api.github.com/users/CyrusNajmabadi","html_url":"https://github.com/CyrusNajmabadi","followers_url":"https://api.github.com/users/CyrusNajmabadi/followers","following_url":"https://api.github.com/users/CyrusNajmabadi/following{/other_user}","gists_url":"https://api.github.com/users/CyrusNajmabadi/gists{/gist_id}","starred_url":"https://api.github.com/users/CyrusNajmabadi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/CyrusNajmabadi/subscriptions","organizations_url":"https://api.github.com/users/CyrusNajmabadi/orgs","repos_url":"https://api.github.com/users/CyrusNajmabadi/repos","events_url":"https://api.github.com/users/CyrusNajmabadi/events{/privacy}","received_events_url":"https://api.github.com/users/CyrusNajmabadi/received_events","type":"User","site_admin":false},"created_at":"2016-11-02T09:22:59Z","updated_at":"2016-11-02T09:22:59Z","body":"Let's keep the conversation on topic.  Thanks :)\r\n\r\n> Doesn't this outweigh 'low profile' of _ ?\r\n\r\nCurrently we don't think so.  \"_\" as a wildcard fits into how people are generally using that identifier already today.  So we think it's nice to be able to just codify that concept, even if it means we do need to put in the due diligence to make sure we don't break any existing code.\r\n"}}
{"actor":{"display_login":"CyrusNajmabadi"}}