Skip to content

Ref with null suppression operator is not considered a value write #58161

@sharwell

Description

@sharwell

Version Used: Version 17.1.0 Preview 2.0 [31928.29.main]

Steps to Reproduce:

public static T EnsureInitialized<T>([NotNull] ref T? target, Func<T> valueFactory) where T : class
    => Volatile.Read(ref target!) ?? InterlockedStore(ref target!, valueFactory());

public static T EnsureInitialized<T, U>([NotNull] ref T? target, Func<U, T> valueFactory, U state)
    where T : class
{
    return Volatile.Read(ref target!) ?? InterlockedStore(ref target, valueFactory(state));
}

image

Expected Behavior:

target should be underlined in both methods.

Actual Behavior:

target is only underlined in the method which contains ref target (as opposed to ref target!.

Metadata

Metadata

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions