Skip to content

Commit

Permalink
Clarify task types (#875)
Browse files Browse the repository at this point in the history
* Clarify task types

- `Task` and `Task<T>` are classified as task types despite not
  specifying builder types
- Interfaces are allowed to be task types
- Enums and methods are prohibited from being decorated with
  AsyncMethodBuilderAttribute
- Task types must not be generic in more than one type parameter
  (including in terms of containing types)

Discussion required for all of this, but if merged, would
fix #854, #856, #858 and #859.

* Prevent nesting within generic types, for task types.

This wording follows the wording in 15.15.2 for task builders.
  • Loading branch information
jskeet authored Aug 15, 2023
1 parent 74aed31 commit c48d041
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 4 deletions.
3 changes: 1 addition & 2 deletions standard/classes.md
Original file line number Diff line number Diff line change
Expand Up @@ -5207,8 +5207,7 @@ A method ([§15.6](classes.md#156-methods)) or anonymous function ([§12.19](exp
It is a compile-time error for the formal parameter list of an async function to specify any `in`, `out`, or `ref` parameters, or any parameter of a `ref struct` type.
The *return_type* of an async method shall be either `void` or a ***task type***. For an async method that returns a value, a task type shall be generic. For an async method that does not return a value, a task type shall not be generic. Such types are referred to in this specification asTaskType»<T>` andTaskType»`, respectively. (The Standard library type `System.Threading.Tasks.Task` and types constructed from `System.Threading.Tasks.Task<TResult>` are task types.)
A task type shall be a class or struct type that is associated with a ***task builder type*** via the attribute `System.Runtime.CompilerServices.AsyncMethodBuilderAttribute`. Such types are referred to in this specification asTaskBuilderType»<T>` andTaskBuilderType»`.
The *return_type* of an async method shall be either `void` or a ***task type***. For an async method that returns a value, a task type shall be generic. For an async method that does not return a value, a task type shall not be generic. Such types are referred to in this specification asTaskType»<T>` andTaskType»`, respectively. The Standard library type `System.Threading.Tasks.Task` and types constructed from `System.Threading.Tasks.Task<TResult>` are task types, as well as a class, struct or interface type that is associated with a ***task builder type*** via the attribute `System.Runtime.CompilerServices.AsyncMethodBuilderAttribute`. Such types are referred to in this specification asTaskBuilderType»<T>` andTaskBuilderType»`. A task type can have at most one type parameter and cannot be nested in a generic type.
An async method returning a task type is said to be ***task-returning***.
Expand Down
3 changes: 1 addition & 2 deletions standard/standard-library.md
Original file line number Diff line number Diff line change
Expand Up @@ -463,8 +463,7 @@ namespace System.Linq.Expressions
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct |
AttributeTargets.Interface | AttributeTargets.Delegate |
AttributeTargets.Enum | AttributeTargets.Method,
AttributeTargets.Interface,
Inherited = false, AllowMultiple = false)]
public sealed class AsyncMethodBuilderAttribute : Attribute
{
Expand Down

0 comments on commit c48d041

Please sign in to comment.