{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/9523","repository_url":"https://api.github.com/repos/dotnet/roslyn","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/9523/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/9523/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/9523/events","html_url":"https://github.com/dotnet/roslyn/issues/9523","id":139014105,"number":9523,"title":"Proposal: Nested local type declarations ","user":{"login":"jnm2","id":8040367,"avatar_url":"https://avatars.githubusercontent.com/u/8040367?v=3","gravatar_id":"","url":"https://api.github.com/users/jnm2","html_url":"https://github.com/jnm2","followers_url":"https://api.github.com/users/jnm2/followers","following_url":"https://api.github.com/users/jnm2/following{/other_user}","gists_url":"https://api.github.com/users/jnm2/gists{/gist_id}","starred_url":"https://api.github.com/users/jnm2/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jnm2/subscriptions","organizations_url":"https://api.github.com/users/jnm2/orgs","repos_url":"https://api.github.com/users/jnm2/repos","events_url":"https://api.github.com/users/jnm2/events{/privacy}","received_events_url":"https://api.github.com/users/jnm2/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"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2016-03-07T15:54:08Z","updated_at":"2016-03-07T23:11:24Z","closed_at":null,"body":"Extend the languages to support the declaration of types in block scope.\r\n\r\nAs per [gafter's instructions](https://github.com/dotnet/roslyn/issues/259#issuecomment-193063943). This would be a terrific feature for the same reasons as local functions: scoping, keeping together when moving, visually closer to the usage."},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/193497597","html_url":"https://github.com/dotnet/roslyn/issues/9523#issuecomment-193497597","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/9523","id":193497597,"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":"2016-03-07T23:11:24Z","updated_at":"2016-03-07T23:11:24Z","body":"@jnm2 \r\n\r\nPossibly.  What the compiler does now for lambdas that enclose `this` or member access is that it emits a private nested type that has a field of that type and it assigns that field to `this`, then it just performs the member access directly.  Something like this:\r\n\r\n```cs\r\npublic void DoStuff() {\r\n    string greetings = \"Hello\";\r\n    Action action = () => Console.WriteLine(greetings + \" \" + this.ToString());\r\n}\r\n\r\n// becomes\r\nprivate void DoStuff_DisplayClass {\r\n    public C _this;\r\n    public string _greetings;\r\n\r\n    public void action() {\r\n        Console.WriteLine(_greetings + \" \" + _this.ToString());\r\n    }\r\n}\r\n\r\npublic void DoStuff() {\r\n    DoStuff_DisplayClass temp = new DoStuff_DisplayClass();\r\n    temp._this = this;\r\n    temp._greetings = \"Hello\";\r\n    Action action = temp.action;\r\n}\r\n```\r\n\r\nI don't know if local functions did this differently, it was mentioned that they could silently insert `ref` parameters instead of needing to assign fields.\r\n\r\nAs for local types, I do imagine that if you omit a constructor that one would be created which might accept `this` or other enclosed state, or if you do specify a constructor that it is silently amended to include those additional parameters.  That wouldn't be unlike nested types in Java that automatically get a `this` parameter even when they're not local types."}}