Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Proposal]: Task<T> nullability covariance #8997

Open
333fred opened this issue Jan 6, 2025 · 0 comments
Open

[Proposal]: Task<T> nullability covariance #8997

333fred opened this issue Jan 6, 2025 · 0 comments
Assignees
Milestone

Comments

@333fred
Copy link
Member

333fred commented Jan 6, 2025

Task<T> nullability covariance

Summary

Task<T> nullability covariance (LDM tentatively approved, needs design proposal for task-like types)

It should be possible to return a Task<string!> for a Task<string?>.

using System.Threading.Tasks;
#nullable enable
public class C 
{
    public Task<(bool Result, string? Extras)> M() 
    {
        return Task.FromResult((true, "")); // currently produces a warning
    }
}

Design meetings

Split issue from #3868
https://github.com/dotnet/csharplang/blob/main/meetings/2022/LDM-2022-09-28.md#nullability-improvements
https://github.com/dotnet/csharplang/blob/main/meetings/2024/LDM-2024-09-06.md#taskt-nullability-covariance

@333fred 333fred added this to the Backlog milestone Jan 6, 2025
@dotnet dotnet locked and limited conversation to collaborators Jan 6, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants