-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersArea-Language DesignFeature - Nullable Reference TypesNullable Reference TypesNullable Reference Types
Milestone
Description
Examples, with placeholder attributes:
// ensures arg is true
static void Assert([EnsuresTrue] bool b);// false if arg is not null
static bool IsNullOrEmpty([NotNullWhenFalse] string? s)// reference equality for null
[NullEquals] static bool Equals(object? x, object? y)// result nullability matches arg
static string? NormalizePath([NullInNullOut] string? path)// ref arg not reset to null
static void InitializeAndAdd<T>([NotNulled] ref List<T>? list, T item)(jcouv updated): We also need to handle:
Interlocked.CompareExchange- a ref parameter which has a non-null inbound value, but possibly null outbound value (see
FilterAndAppendAndFreeDiagnostics). This way the caller would be warned if passing a maybe-null argument. (Debug.Assertwould not do that) TryGetValueonWeakReferenceobject.ReferenceEquals- Would it be possible to hint that
AsNode()is safe ifIsNodeis true? - Should those attribute affect the inferred type?
var x = EnsuresNotNull(something); - What about
M(x = y, y)whereEnsuresNotNullis on the second parameter, orM(y, x = y)where it is on the first?
Filed https://github.com/dotnet/corefx/issues/33880 to track work to annotate the BCL and collect ideas of APIs needing annotations.
We should confirm whether the nullable attributes should be added to mono or not.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-CompilersArea-Language DesignFeature - Nullable Reference TypesNullable Reference TypesNullable Reference Types