@@ -123648,5 +123648,65 @@ void Method(Program x)
123648123648 Assert.Equal(CodeAnalysis.NullableAnnotation.None, model.GetTypeInfo(identifiers[3]).Nullability.Annotation);
123649123649 // Note: this discrepancy causes some issues with type simplification in the IDE layer
123650123650 }
123651+
123652+ [Fact, WorkItem(39417, "https://github.com/dotnet/roslyn/issues/39417")]
123653+ public void ConfigureAwait_DetectSettingNullableToNonNullableType()
123654+ {
123655+ var source =
123656+ @"using System.Threading.Tasks;
123657+ #nullable enable
123658+ class Request
123659+ {
123660+ public string? Name { get; }
123661+ public Task<string?> GetName() => Task.FromResult(Name);
123662+ }
123663+ class Handler
123664+ {
123665+ public async Task Handle(Request request)
123666+ {
123667+ string a = request.Name;
123668+ string b = await request.GetName().ConfigureAwait(false);
123669+ }
123670+ }
123671+ ";
123672+ var comp = CreateCompilation(source);
123673+ comp.VerifyDiagnostics(
123674+ Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "request.Name").WithLocation(12, 20),
123675+ Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "await request.GetName().ConfigureAwait(false)").WithLocation(13, 20)
123676+ );
123677+ }
123678+
123679+ [Fact, WorkItem(39417, "https://github.com/dotnet/roslyn/issues/39417")]
123680+ public void CustomAwaitable_DetectSettingNullableToNonNullableType()
123681+ {
123682+ var source =
123683+ @"using System.Runtime.CompilerServices;
123684+ using System.Threading.Tasks;
123685+ #nullable enable
123686+ static class TaskExtensions
123687+ {
123688+ public static ConfiguredTaskAwaitable<TResult> NoSync<TResult>(this Task<TResult> task)
123689+ {
123690+ return task.ConfigureAwait(false);
123691+ }
123692+ }
123693+ class Request
123694+ {
123695+ public string? Name { get; }
123696+ public Task<string?> GetName() => Task.FromResult(Name);
123697+ }
123698+ class Handler
123699+ {
123700+ public async Task Handle(Request request)
123701+ {
123702+ string a = await request.GetName().NoSync();
123703+ }
123704+ }
123705+ ";
123706+ var comp = CreateCompilation(source);
123707+ comp.VerifyDiagnostics(
123708+ Diagnostic(ErrorCode.WRN_ConvertingNullableToNonNullable, "await request.GetName().NoSync()").WithLocation(20, 20)
123709+ );
123710+ }
123651123711 }
123652123712}
0 commit comments