Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

§12.8.4 Simple names doesn't cover finalizers

Aperta Adatta ai principianti
#1,830 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
1/5
Tempo stimato
Meno di un'ora
Idoneità per principianti
76/100
Tipo di issue
Documentazione
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
csharp
Ambito
documentation

Direzione di ricerca

Leggi §12.8.4 in standard/expressions.md, poi confronta i relativi contesti dei membri di istanza con §12.8.14 e §12.8.15, a cui rimanda l’issue. Aggiungi finalizers ai contesti elencati affinché i nomi semplici dei membri di istanza vengano risolti come this.I; il lavoro è completato quando la formulazione corrisponde al testo previsto nell’issue.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.

Lingua principale
C#
Stelle
818
Fork
99
Merge medio
1g 16h
PR unite (30g)
14

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di dotnet/csharpstandard

Tutte le issue di dotnet/csharpstandard

Issue simili

Altre issue su C#

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.