Operator precedence for x?.y seems to be listed wrong #26112
Labels
doc-bug
Problem with the content; needs to be fixed [org][type][category]
dotnet-csharp/svc
lang-reference/subsvc
okr-quality
Content-quality KR: Concerns article defects (bugs), freshness, or build warnings.
Pri1
High priority, do before Pri2 and Pri3
📌 seQUESTered
Identifies that an issue has been imported into Quest.
Under the section "Operator precedence" the following are listed as having equal precedence: "x.y" and "x?.y"
Also none of them are listed as being right associative.
This would then mean that the following two lines should be semantically identical:
var x = a.b?.c.d;
var x = (a.b?.c).d;
This how ever is not how the language works!
The first example will never try to access d on c if b is null. The final result will simply be null if b is null.
in the second example it will try to access d on the result of the expression in parentheses, even if b is null. (resulting in a null reference exception if b is null)
I am not sure exactly where in the precedence hierarchy "x?.y" belongs, but at least lower than primary expressions.
Document Details
⚠ Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.
Associated WorkItem - 123095
The text was updated successfully, but these errors were encountered: