§12.8.4 Simple names doesn't cover finalizers
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 1/5
- Estimated time
- Under an hour
- Newbie friendliness
- 76/100
- Issue type
- Documentation
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- csharp
- Domain
- documentation
Research direction
Read §12.8.4 in standard/expressions.md, then compare its instance-member contexts with §12.8.14 and §12.8.15, which the issue links. Add finalizers to the listed contexts so simple instance-member names resolve as this.I; done when the wording matches the expected text in the issue.
Written by the indexing model from the issue text.
Description
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
Tis 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 formthis.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.IorT.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
Tis 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 formthis.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.
- Dominant language
- C#
- Stars
- 817
- Forks
- 99
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 14
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from dotnet/csharpstandard
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
dotnet/csharpstandard#1629 ·
Maintainers usually reply within 1 day
-
type: clarity
Difficulty 1/5 Under an hour Newbie friendliness 82/100
dotnet/csharpstandard#599 ·
Maintainers usually reply within 1 day
-
9.3.6 Char setOpentype: clarity
Difficulty 1/5 Under an hour Newbie friendliness 68/100
dotnet/csharpstandard#189 · 5 comments ·
Maintainers usually reply within 1 day
-
Jon to check Word converter warnings before C# 8 releasePossibly taken @jskeet claimed this 4 days ago. Open
dotnet/csharpstandard#1828 · 1 assignee ·
Maintainers usually reply within 1 day
-
Nigel to update the grammar checker for C# 8May be free again @Nigel-Ecma claimed this 32 days ago, and no pull request is open. Open
dotnet/csharpstandard#1805 · 1 comment · 1 assignee ·
Maintainers usually reply within 1 day
All issues in dotnet/csharpstandard
Similar issues
-
A numeric literal is parsed in the host's culture, so 1.5 is 15 in a made EXE on a comma-decimal OSOpenbug interpreter silently-wrong small
Difficulty 2/5 1-3 hours Newbie friendliness 83/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 66/100
reactiveui/ReactiveUI.Binding.SourceGenerators#176 ·
Maintainers usually reply within 1 day
-
c:docs p:high size:S t:docs
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
lugassawan/swe-workbench#799 ·
Maintainers usually reply within 1 day