提交 e22ee01c 编写于 作者: F Fabrício Godoy

Test convert nullable to non-nullable using custom awaitable (#39417)

上级 15970738
...@@ -123648,5 +123648,65 @@ void Method(Program x) ...@@ -123648,5 +123648,65 @@ void Method(Program x)
Assert.Equal(CodeAnalysis.NullableAnnotation.None, model.GetTypeInfo(identifiers[3]).Nullability.Annotation); Assert.Equal(CodeAnalysis.NullableAnnotation.None, model.GetTypeInfo(identifiers[3]).Nullability.Annotation);
// Note: this discrepancy causes some issues with type simplification in the IDE layer // 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)
);
}
} }
} }
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册