csharplang/proposals/csharp-8.0/shadowing-in-nested-functions.md
Charles Stoner a0b59a6768
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.
2020-10-19 12:56:27 -07:00

1.5 KiB

Name shadowing in nested functions

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