Invariant meaning in blocks
For each occurrence of a given identifier as a simple-name in an expression or declarator, every other occurrence of the same identifier as a simple-name in an expression or declarator within the immediately enclosing block (§8.2) or switch-block (§8.7.2) must refer to the same entity. This rule ensures that the meaning of a name is always the same within a block. The example class Test void F(bool b) { results in a compile-time error because x refers to different entities within the outer block (the extent of which includes the nested block in the if statement). In contrast, the example class Test void F(bool b) { is permitted because the name x is never used in the outer block. Note that the rule of invariant meaning applies only to simple names. It is perfectly valid for the same identifier to have one meaning as a simple name and another meaning as right operand of a member access (§7.5.4). For example: struct Point public Point(int x, int y) { The example above illustrates a common pattern of using the names of fields as parameter names in an instance constructor. In the example, the simple names x and y refer to the parameters, but that does not prevent the member access expressions this.x and this.y from accessing the fields.
|