Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -161655,5 +161655,94 @@ public static void M1(Func<Task> f) { }
// c1.
Diagnostic(ErrorCode.ERR_SemicolonExpected, "").WithLocation(15, 20));
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51191")]
public void InterlockedExchange_WithNullCheckAndNullArgument()
{
var source = """
#nullable enable

using System.Threading;

public class C {
private C? _obj;

public void Rent()
{
if (_obj is not null)
{
C? o = Interlocked.Exchange(ref _obj, null);
if (o is not null)
{
Use(o);
}
}
}

private void Use(C o) {}
}
""";
CreateCompilation(source).VerifyDiagnostics();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51191")]
public void InterlockedCompareExchange_WithNullCheckAndNullArgument()
{
var source = """
#nullable enable

using System.Threading;

public class C {
private C? _obj;

public void Rent()
{
C? current = _obj;
if (current is not null)
{
C? o = Interlocked.CompareExchange(ref _obj, null, current);
if (o is not null)
{
Use(o);
}
}
}

private void Use(C o) {}
}
""";
CreateCompilation(source).VerifyDiagnostics();
}

[Fact, WorkItem("https://github.com/dotnet/roslyn/issues/51191")]
public void InterlockedExchange_WithExplicitTypeArgument()
{
var source = """
#nullable enable

using System.Threading;

public class C {
private C? _obj;

public void Rent()
{
if (_obj is not null)
{
// Explicitly specifying the type argument should also work
C? o = Interlocked.Exchange<C?>(ref _obj, null);
if (o is not null)
{
Use(o);
}
}
}

private void Use(C o) {}
}
""";
CreateCompilation(source).VerifyDiagnostics();
}
}
}