dotnet / dotnet/csharpstandard

12.7.3.2 Ambiguous language

Open
#109 12 comments 0 reactions 0 assignees View on GitHub
type: clarity
Dominant language
C#
Stars
815
Forks
99
Avg merge
1d 14h
Merged PRs (30d)
16

Description

I found this part of the proposed standard hard to read, and the note contradictory:

> For each occurrence of a given identifier as a full simple-name (without a type argument list) in an expression or declarator, within the local variable declaration space (§9.3) immediately enclosing that occurrence, every other occurrence of the same identifier as a full simple-name in an expression or declarator shall refer to the same entity. [Note: This rule ensures that the meaning of a name is always the same within a given block, switch block, for-, foreach- or using-statement, or anonymous function. end note]

The rule _doesn't_ ensure that the meaning of a name is always the same within a given block, as this is entirely valid:

``` csharp
{
{
int x = 10;
}
{
string x = "other";
}
}
```

You could argue that "within a given block [...]" doesn't include nested blocks, but then the "error" example in the standard wouldn't fall foul of the rule.

It seems it's really "within a given block [...] that immediately uses that name" - but I hope we can find a better way of expressing this.

It's worth noting that this rule has been removed from C# 6. While I'd love to propose that we ditch it in the standard one version early, that would feel a little cavalier to say the least...

See also:
- https://github.com/dotnet/roslyn/issues/2110
- http://stackoverflow.com/questions/29750618

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.