Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

§12.8.4 Simple names doesn't cover finalizers

Open Beginner friendly
#1,830 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
1/5
Estimated time
Under an hour
Newbie friendliness
76/100
Issue type
Documentation
Clarity
Clearly specified
Activity status
Active
Tech stack
csharp
Domain
documentation

Research direction

Read §12.8.4 in standard/expressions.md, then compare its instance-member contexts with §12.8.14 and §12.8.15, which the issue links. Add finalizers to the listed contexts so simple instance-member names resolve as this.I; done when the wording matches the expected text in the issue.

Written by the indexing model from the issue text.

Description

Describe the bug

In draft-v8, §12.8.4 Simple names turns a simple name that refers to an instance member into this.I only in these cases:

Otherwise, if T is the instance type of the immediately enclosing class or struct type, if the lookup identifies an instance member, and if the reference occurs within the block of an instance constructor, an instance method, or an instance accessor (§12.2.1), the result is the same as a member access (§12.8.7) of the form this.I.

Finalizers aren't in that list. In a finalizer, a simple name for an instance member falls through to the next bullet:

Otherwise, the result is the same as a member access (§12.8.7) of the form T.I or T.I<A₁, ..., Aₑ>.

When T is a type, §12.8.7 Member access handles only static members and nested types, then says "Otherwise, E.I is an invalid member reference, and a compile-time error occurs." So by the standard's wording, x = 0; in a finalizer is an error, even though compilers accept it.

§12.8.14 This access and §12.8.15 Base access both list finalizers explicitly, so the omission looks unintentional.

Finalizers have been in the language since C# 1, so this is in scope for the C# 8 standard.

Example

This compiles today:

class C
{
    private int x;

    ~C()
    {
        x = 0;  // simple name for an instance field in a finalizer
        M();    // simple name for an instance method in a finalizer
    }

    void M() { }
}

Expected behavior

§12.8.4 should list finalizers alongside the other contexts, as §12.8.14 and §12.8.15 do:

Otherwise, if T is the instance type of the immediately enclosing class or struct type, if the lookup identifies an instance member, and if the reference occurs within the block of an instance constructor, an instance method, an instance accessor (§12.2.1), or a finalizer, the result is the same as a member access (§12.8.7) of the form this.I.

Additional context

§15.13 Finalizers says a finalizer's body "corresponds exactly to the method_body of an instance method." If that were meant to make a finalizer's body count as an instance method's block here, §12.8.14 and §12.8.15 wouldn't need to list finalizers. #577 asks what "corresponds exactly to" means.

The same sentence says block, which doesn't cover expression bodies. That's the same problem #1434 describes for "block body," so I've left it out of this issue.

Dominant language
C#
Stars
817
Forks
99
Avg merge
1d 16h
Merged PRs (30d)
14

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from dotnet/csharpstandard

All issues in dotnet/csharpstandard

Similar issues

More C# issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.