Counterintuitive interaction of null-conditional and null-forgiving operators #43659
Labels
Area-Compilers
Area-Language Design
New Language Feature - Nullable Reference Types
Nullable Reference Types
Milestone
According to the documentation, the null-forgiving operator has no effect at run time. However, it has a surprising side effect of breaking a
null_conditional_operations
chain at compile time, which may change evaluation of the expression. Consider this example:Adding the
!
operator effectively changes parsing of the expression to(a?.First())!.ToString()
. Since this behavior is surprising for many developers (e.g., dotnet/docs#17988), I am wondering whether not allowing!
innull_conditional_operations
was due to omission rather than intentional design. In the former case we might consider fixing this, in the latter — I would like to learn arguments that led to this decision.The text was updated successfully, but these errors were encountered: