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
out-of-line destructor syntax seems inconsistent with other declaration forms #2567
Comments
Hi! i wanna work on this. Please assign me this task, |
@AnonymousDeveloper156 See our contributing guide:
|
This comment was marked as off-topic.
This comment was marked as off-topic.
I started a discussion in Discord about potential names for the
One potential advantage for all three is that they are verbs, which matches the common naming of a function like this. |
Our syntax for an out-of-line definition of a destructor looks like this:
In all other declaration forms, when we have
introducer_keyword identifier
, theidentifier
is the name of the entity being declared. However, in this case, the nameC
isn't being declared; rather, its destructor is being declared. This seems inconsistent.#1154 doesn't list any considered syntactic alternatives for its chosen form of destructor (as a special function-like member). Here are a few we should explicitly consider:
fn <special>[self: Self]();
andfn Class.<special>[self: Self]() {}
. Choices for the "special name" include:destructor
, where we keepdestructor
as a keyword:fn destructor[self: Self]();
orfn Class.destructor[self: Self]() {}
. This somewhat parallels what we do with thebase
keyword as a pseudo-member-name.~
:fn ~[self: Self]()
orfn Class.~[self: Self]() {}
. This mirrors the current idea of using~
as an operator to express destructive ownership transfer.~Self
:fn ~Self[self: Self]()
orfn Class.~Self[self: Self]() {}
. This would be very C++-like.()
.for
keyword afterdestructor
:destructor for C [self: Self] {}
.The text was updated successfully, but these errors were encountered: