Skip to content

Conversation

glihm
Copy link
Contributor

@glihm glihm commented Jul 26, 2020

Fixes #4397

Summary

As described in the issue, ValueTask and ValueTask<TResult> are lacking of information about default constructors behavior.
This PR is adding a note reworded from the code itself.

@dotnet-bot dotnet-bot added this to the July 2020 milestone Jul 26, 2020
@gewarren gewarren requested review from tarekgh and stephentoub August 3, 2020 17:37
@tarekgh
Copy link
Member

tarekgh commented Aug 3, 2020

I am not sure it is a good idea to document the default constructor that is automatically generated by the compiler. Usually users shouldn't use the default constructor. and If using the default value, should be used to indicate if the instance is not initialized or not similar to null for the instance types. This is a generic issue for the whole framework structs.

I'll let @stephentoub comment on that but his response may be delayed a little.

@stephentoub
Copy link
Member

Documenting what the status of a zero-initialized ValueTask/ValueTask<T> is fine, though it's not really using a "default constructor" when it does so, so I'd be careful with such language.

@glihm
Copy link
Contributor Author

glihm commented Aug 7, 2020

@tarekgh @stephentoub thanks for the feedback, I'll try a rewording to avoid such confusion. 👍🏻

@glihm
Copy link
Contributor Author

glihm commented Aug 13, 2020

In struct documentation, those lines are written:

You can't declare a parameterless constructor.
Every structure type already provides an implicit parameterless constructor that produces the default value of the type.

changing default to parameterless constructor can be less confusing and in the same spirit of struct semantic, what do you think?

@tarekgh
Copy link
Member

tarekgh commented Aug 13, 2020

changing default to parameterless constructor can be less confusing and in the same spirit of struct semantic, what do you think?

I think this can be reasonable but I am not expecting users doing ValueTask v = default will always relate to the parameterless constructor. maybe we can have something like:

An instance created with parameterless constructor or by the default(ValueTask) syntax (a zero initialized structure) represents a synchronously, successfully completed operation. I am sure @stephentoub can rephrase it better :-)

@carlossanlop
Copy link
Contributor

@glihm any chance you can follow up?

Base automatically changed from master to main March 5, 2021 20:52
Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thank you @glihm !

@opbld30
Copy link

opbld30 commented Mar 8, 2021

Docs Build status updates of commit a4e6c60:

✅ Validation status: passed

File Status Preview URL Details
xml/System.Threading.Tasks/ValueTask.xml ✅Succeeded View
xml/System.Threading.Tasks/ValueTask`1.xml ✅Succeeded View

For more details, please refer to the build report.

Note: Broken links written as relative paths are included in the above build report. For broken links written as absolute paths or external URLs, see the broken link report.

For any questions, please:

@adamsitnik adamsitnik merged commit 21e9128 into dotnet:main Mar 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Document ValueTask default constructor
7 participants