You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#nullable enable
publicclassC{publicstaticstring?field;publicstrings= field.ToString();// no warningpublicvoidM()=> field.ToString();// warning CS8602: Possible dereference of a null reference.}
This is also a problem when directly assigning null to a non-nullable member. However, it only arises if there is no explicit constructor (or static constructor, for static variables). For instance:
using System;
#nullable enable
classMyObject{publicstaticstringmyStaticString=null;//no warningpublicstringmyString=null;//no warning}classMyOtherObject{publicstaticstringmyStaticString=null;//correct warningstaticMyOtherObject(){}publicstringmyString=null;//correct warningpublicMyOtherObject(){}}
Version Used:
Branch C# 8.0: Nullable reference type (29 Oct 2018)
https://github.com/dotnet/csharplang/blob/master/proposals/nullable-reference-types.md
Latest commit 2f8fef by AlekseyTs:
Compare Nullable modifiers while comparing type symbols by default. (#30770)
Steps to Reproduce:
Compile the following code
https://sharplab.io/#v2:EYLgZgpghgLgrgJwgZwLQDk4BstWFiAJQkiQDsBjCAFQE8AHFAHwGIztd8IACCMvAgFgAUAAEAzN1EAmbgGFuAbxHdVUyaICMANimaADAH5uYAJYQsAEwDcKtRL37uybgF4T5qwDpqAewDKMAimZADmABQAlNbcAPSx3GS+3ADuUAhkIaF2qg6iACzcALJRbgB8HhaWPgFBWVEx8anpmWEiAL5AA
Expected Behavior:
Consistent warnings for both dereferencing of
field
.Actual Behavior:
Field initializer does not have the warning
The text was updated successfully, but these errors were encountered: