dotnet / dotnet/csharpstandard
nameof can refer to a variable "early"
Open
type: bug
- Dominant language
- C#
- Stars
- 815
- Forks
- 99
- Avg merge
- 1d 14h
- Merged PRs (30d)
- 16
Description
Spotted in #608 by @KalleOlaviNiemitalo, but split off as it's not part of the change.
In statements.md:
> The scope of a local constant is the block in which the declaration occurs. It is an error to refer to a local constant in a textual position that precedes the end of its *constant_declarator*.
But `const string s = nameof(s);` is fine, despite the reference in `nameof(s)` being before the end of the declarator.
It's possible that we just need a carve-out for nameof in this case.
Contributor guide
Assessment
This issue has not been assessed yet.