Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Reserved member names for non-methods #1307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
KalleOlaviNiemitalo opened this issue Apr 10, 2025 · 1 comment
Open

Reserved member names for non-methods #1307

KalleOlaviNiemitalo opened this issue Apr 10, 2025 · 1 comment

Comments

@KalleOlaviNiemitalo
Copy link
Contributor

KalleOlaviNiemitalo commented Apr 10, 2025

Describe the bug

C# 7 section 15.3.10.1 (Reserved member names / General) says

It is a compile-time error for a program to declare a member whose signature matches a signature reserved by a member declared in the same scope, even if […]

But it should also be a compile-time error if the program declares a non-method member whose name matches such a reserved name, even though the signature won't match then.

Example

class C {
    ~C() {}

    struct Finalize {};
}

Expected behavior

This should be a compile-time error.

Additional context

Inspired by #1302.

@KalleOlaviNiemitalo
Copy link
Contributor Author

KalleOlaviNiemitalo commented Apr 10, 2025

Another case

using System.Runtime.CompilerServices;
class C {
    ~C() {}

    // error CS0102: The type 'C' already contains a definition for 'Finalize'
    [IndexerName("Finalize")]
    int this[int i] => 0;
}

Here, the indexer would be encoded in ECMA-335 metadata as an indexed property named Finalize and a method named get_Finalize. The property then clashes with the reserved method name of the ~C() finalizer but neither ECMA-334 nor ECMA-335 seems to forbid the name from being overloaded in this way.

See also #1303 about IndexerNameAttribute in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant