-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Make annotations between Task.Exception and Task.Status=Failed possible to allow usage without the dammit operator #2720
Comments
I hope some concept like associating value with enum members in Rust can be introduced. That solves the problem better. |
@huoyaoyuan Not totally on topic, but the concept you're referring to is called discriminated unions. There's a C# X.0 feature suggestion if you're interested in following it or participating in the discussion. |
@PathogenDavid If discriminated union has been added, we can expose members of |
Sure we could've, but that ship has sailed. The |
On a more on-topic note: @jcouv has previously stated that this sort of thing would be a whole new feature on top of what already exists for nullable reference types. |
I think for post conditions like that, code contracts (#105) would be ideal: public AggregateException Exception
{
get ensures return != null when Status == TaskStatus.Faulted;
} |
I wouldn't bet on method contracts coming along and solving this problem. The implementation from Microsoft Research had a whole host of problems and very poor performance. Although it predates Roslyn, I have severe doubts it would be able to be integrated into something as performance-sensitive as a compiler. |
Work on this is underway and tracked at dotnet/roslyn#41438. New API at dotnet/runtime#31877. |
There isn't currently a way to annotate
Task.Exception
in the BCL so that the compiler knows that it is not null if and only if the value ofTask.Status
isFaulted
:This would become possible if the C# spec recognized an addition to the current attributes in System.Diagnostics.CodeAnalysis.
Straw man 1:
Straw man 2:
This could be generally useful in other types.
The text was updated successfully, but these errors were encountered: