From e22ee01c85cbd461f1dc7ff7875030e518d32cdf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabr=C3=ADcio=20Godoy?= Date: Sat, 15 Feb 2020 18:29:15 -0300 Subject: [PATCH] Test convert nullable to non-nullable using custom awaitable (#39417) --- .../Semantics/NullableReferenceTypesTests.cs | 60 +++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs index b41bf4c8f41..3ccc93c47c0 100644 --- a/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs +++ b/src/Compilers/CSharp/Test/Semantic/Semantics/NullableReferenceTypesTests.cs @@ -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 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 NoSync(this Task task) + { + return task.ConfigureAwait(false); + } +} +class Request +{ + public string? Name { get; } + public Task 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) + ); + } } } -- GitLab