Add proposals/csharp-8.0/shadowing-in-nested-functions.md (#4036)

* Add proposals/csharp-8.0/shadowing-in-nested-functions.md

* Use enclosing method rather than scope

* Misc.
This commit is contained in:
Charles Stoner 2020-10-19 12:56:27 -07:00 committed by GitHub
parent 8e7d390f6d
commit a0b59a6768
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,3 +1,24 @@
## Name shadowing in nested functions
# Name shadowing in nested functions
In C# 8.0, we added a feature that permits parameters and locals in lambdas and local functions to use names that hide/shadow the names of locals or parameters from the enclosing scope. This is a placholder for its specification.
## Summary
Permit variable names in lambdas and local functions to reuse (and shadow) names from the enclosing method or function.
## Detailed design
With `-langversion:8`, names of locals, local functions, parameters, type parameters, and range variables within a lambda or local function can reuse names of locals, local functions, parameters, type parameters, and range variables from an enclosing method or function. The name in the nested function hides the symbol of the same name from the enclosing function within the nested function.
Shadowing is supported for `static` and non-`static` local functions and lambdas.
There is no change in behavior using `-langversion:7.3` or earlier: names in nested functions that shadow names from the enclosing method or function are reported as errors in those cases.
Any shadowing previously permitted is still supported with `-langversion:8`. For instance: variable names may shadow type and member names; and variable names may shadow enclosing method or local function names.
Shadowing a name declared in an enclosing scope in the same lambda or local function is still reported as an error.
A warning is reported for a type parameter in a local function that shadows a type parameter in the enclosing type, method, or function.
## Design meetings
- https://github.com/dotnet/csharplang/blob/master/meetings/2018/LDM-2018-09-10.md#static-local-functions
- https://github.com/dotnet/csharplang/blob/master/meetings/2019/LDM-2019-01-16.md#shadowing-in-nested-functions