C# grammar "base"

I am looking into the grammar of C# 5.0 and don't quite understand the use of "base". In the reference manual, there is a notion of "base access" defined as:

base-access:
    base   .   identifier
    base   [   expression-list   ]

Where base is a keyword, and it appears that this is the only case. However, I encounter C# inputs such as

base.WithAdditionalDiagnostics<TNode>(node, diagnostics);

Can someone point me out which grammar rule this statement refers to? As 'base' appears to be a normal keyword, not contextual, I assume that there should be a specific grammar rule for this case, and base cannot simply be an identifier.

Jon Skeet
people
quotationmark

I believe it should actually be

base-access:
    base   .   identifier type-argument-list_opt
    base   [   expression-list   ]

... which would make it just like member-access:

member-access:
    primary-expression   .   identifier   type-argument-list_opt
    predefined-type   .   identifier   type-argument-list_opt
    qualified-alias-member   .   identifier   type-argument-list_opt

In other words, in an expression

base.WithAdditionalDiagnostics<TNode>(node, diagnostics);

only

base.WithAdditionalDiagnostics<TNode>

is the base-access part - and the rest is parsed as it would be for other calls such as x.WithAdditionalDiagnostics<TNode>(node, diagnostics).

From section 7.6.8 of the C# 5 spec:

At binding-time, base-access expressions of the form base.I and base[E] are evaluated exactly as if they were written ((B)this).I and ((B)this)[E], where B is the base class of the class or struct in which the construct occurs. Thus, base.I and base[E] correspond to this.I and this[E], except this is viewed as an instance of the base class.

Without the additional type-argument-listopt though, I think your existing expression wouldn't parse.

This is actually specified correctly in the 4th edition of the ECMA-334 specification; I shall raise it as a bug with the C# specification (and make sure it doesn't get broken for the 5th edition).

people

See more on this question at Stackoverflow