From 63d3375bd941419fe405004a2019f5383f7f8ef9 Mon Sep 17 00:00:00 2001 From: Jon Skeet Date: Mon, 7 Aug 2023 15:06:22 +0100 Subject: [PATCH] Clarify task types - `Task` and `Task` 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. --- standard/classes.md | 3 +-- standard/standard-library.md | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/standard/classes.md b/standard/classes.md index 0a3786dee..7a091ab86 100644 --- a/standard/classes.md +++ b/standard/classes.md @@ -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 as `«TaskType»` and `«TaskType»`, respectively. (The Standard library type `System.Threading.Tasks.Task` and types constructed from `System.Threading.Tasks.Task` 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 as `«TaskBuilderType»` and `«TaskBuilderType»`. +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 as `«TaskType»` and `«TaskType»`, respectively. The Standard library type `System.Threading.Tasks.Task` and types constructed from `System.Threading.Tasks.Task` 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 as `«TaskBuilderType»` and `«TaskBuilderType»`. Task types shall be non-generic, or generic in a single type parameter across all containing types. An async method returning a task type is said to be ***task-returning***. diff --git a/standard/standard-library.md b/standard/standard-library.md index 0f1356c54..a3618362a 100644 --- a/standard/standard-library.md +++ b/standard/standard-library.md @@ -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 {