Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

§12.8.4 Simple names doesn't cover finalizers

オープン 初心者向け
#1,830 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
1/5
見積もり時間
1時間未満
初心者へのやさしさ
76/100
issue の種類
ドキュメント
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
csharp
領域
documentation

調査の方向性

standard/expressions.md の §12.8.4 を読み、インスタンスメンバーのコンテキストを、issue がリンクしている §12.8.14 および §12.8.15 と比較してください。単純なインスタンスメンバー名が this.I として解決されるよう、列挙されたコンテキストに finalizer を追加してください。issue の期待されるテキストと文言が一致したら完了です。

索引モデルが issue の本文から書いたものです。

説明

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.

主要言語
C#
スター
818
フォーク
99
平均マージ
1日 16時間
マージ済み PR(30日)
14

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

dotnet/csharpstandard のほかの issue

dotnet/csharpstandard の issue をすべて見る

似ている issue

C# の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。