dotnet / dotnet/csharpstandard

12.7.9 Base access

Open
#186 8 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

12.7.9 Base access says

> When a base-access references a virtual function member (a method, property, or indexer), the determination of which function member to invoke at run-time (§12.6.6) is changed. The function member that is invoked is determined by finding the most derived implementation (§15.6.4) of the function member with respect to B (instead of with respect to the run-time type of this, as would be usual in a non-base access). Thus, within an override of a virtual function member, a base-access can be used to invoke the inherited implementation of the function member. **If the function member referenced by a base-access is abstract, a binding-time error occurs.**

(Emphasis mine)

This would appear to forbid the following legal program, because the member referenced by the base access is abstract. (Note that when we look up `M` in `C2` to determine which member is "referenced" by `base.M`, we apply 12.5 Member lookup, which says "Members that include an override modifier are excluded from the set.")

``` c#
abstract class C1
{
public abstract void M();
}

class C2 : C1
{
public override void M() {}
}

class C3 : C2
{
public override void M() { base.M(); }
}
```

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.