Hacktoberfest 2026: los issues que los mantenedores marcaron para octubre, abiertos y aptos para principiantes. Explorar issues de Hacktoberfest

§12.8.4 Simple names doesn't cover finalizers

Abierto Apto para principiantes
#1,830 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
1/5
Tiempo estimado
Menos de una hora
Aptitud para principiantes
76/100
Tipo de issue
Documentación
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp

Línea de trabajo

Lee §12.8.4 en standard/expressions.md y luego compara sus contextos de miembros de instancia con §12.8.14 y §12.8.15, a los que enlaza el issue. Añade finalizers a los contextos indicados para que los nombres simples de miembros de instancia se resuelvan como this.I; la tarea estará terminada cuando la redacción coincida con el texto esperado en el issue.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C#
Estrellas
818
Forks
99
Merge medio
1 d 16 h
PR fusionados (30 d)
14

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dotnet/csharpstandard

Todos los issues de dotnet/csharpstandard

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.