-
Notifications
You must be signed in to change notification settings - Fork 1k
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
C#6 draft spec specification discrepancy in "Reference type equality operators" section for nullable value types #3359
Comments
I don't see a problem.
This doesn't apply to the case of class C<T>
{
void F(T x) {
if (x == null) throw new ArgumentNullException();
...
}
} because |
@bbarry Yes, that makes the Equality operators and null / 12.11.10 Equality operators between nullable value types and the null literal of the respective specs not apply to the generic case. The issue stems from the (12.11.7) Reference type equality operators. I will make an edit/add note to the issue. |
The same problem also occurs in this docs section:
false! should be something like
|
closing as this is fixed in the dotnet/csharpstandard repo for the C# 6 draft. |
A sub-heading of the issue could be: reference type vs. value type vs. nullable (value/reference?) type
Basic problem: in a generic class with unconstrained T, for some T x,
x == null
is NOT always false for value types: when T is nullable value type, it depends on the HasValue property!The current publicly searchable specification (C#6 draft) differs from C#5 (final spec) and (most probably) the compiler/JIT reality.
It's quite unfortunate the C#6 draft still contains error comming from the original MS C#5 spec, which were corrected in the finalized/ECMA C#5 spec.
Refers to dotnet/docs#8251 (I read it while being half-way through writing this issue 🙄... After googling "C# language specification", going on the end of the page, finding "Formal C# Language Specification" issue 😢)
The "current public spec" https://github.com/dotnet/csharplang/blob/892af9016b/spec/expressions.md#reference-type-equality-operators (current version) being fed into
https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/language-specification/expressions#reference-type-equality-operators
which claims to be draft of C#6 spec, says:
While the C#5 spec says:
There are more differences between C#5 and C#6 draft in these sections, for example C#5 spec "guarantees" that no boxing occurs:
=============
Note: There is also a section about [Nullable] == null in the spec, and that one is the same in both. This section does not apply to the problem, it only applies when the expression is (known to be) of a nullable type.
C#6 draft
C#5: 12.11.10 Equality operators between nullable value types and the null literal
Edit: removed the citation of "Equality operators and null" / "12.11.10 Equality operators between nullable value types and the null literal" sections as they are not vital to the issue.
Edit #2: I made the important parts of citations bold and the introduction of issues more clear.
The text was updated successfully, but these errors were encountered: