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 @@ -123648,5 +123648,65 @@ void Method(Program x)
Assert.Equal(CodeAnalysis.NullableAnnotation.None, model.GetTypeInfo(identifiers[3]).Nullability.Annotation);
// Note: this discrepancy causes some issues with type simplification in the IDE layer
}

[Fact, WorkItem(39417, "https://github.com/dotnet/roslyn/issues/39417")]
public void ConfigureAwait_DetectSettingNullableToNonNullableType()
{
var source =
@"using System.Threading.Tasks;
#nullable enable
class Request
{
public string? Name { get; }
public Task<string?> GetName() => Task.FromResult(Name);
}
class Handler
{
public async Task Handle(Request request)
{
string a = request.Name;
string b = await request.GetName().ConfigureAwait(false);
}
}
";
var comp = CreateCompilation(source);
comp.VerifyDiagnostics(
Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "request.Name").WithLocation(12, 20),
Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "await request.GetName().ConfigureAwait(false)").WithLocation(13, 20)
);
}

[Fact, WorkItem(39417, "https://github.com/dotnet/roslyn/issues/39417")]
public void CustomAwaitable_DetectSettingNullableToNonNullableType()
{
var source =
@"using System.Runtime.CompilerServices;
using System.Threading.Tasks;
#nullable enable
static class TaskExtensions
{
public static ConfiguredTaskAwaitable<TResult> NoSync<TResult>(this Task<TResult> task)
{
return task.ConfigureAwait(false);
}
}
class Request
{
public string? Name { get; }
public Task<string?> GetName() => Task.FromResult(Name);
}
class Handler
{
public async Task Handle(Request request)
{
string a = await request.GetName().NoSync();
}
}
";
var comp = CreateCompilation(source);
comp.VerifyDiagnostics(
Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "await request.GetName().NoSync()").WithLocation(20, 20)
);
}
}
}