dotnet / docs

This repository contains .NET Documentation.
https://learn.microsoft.com/dotnet
Creative Commons Attribution 4.0 International
4.26k stars 5.89k forks source link

Wrong clerification of the terms statement and expression #20483

Closed mpostol closed 3 years ago

mpostol commented 4 years ago

T result = await SomeTaskMethodAsync<T>(); looks like statement but not expression. `await SomeTaskMethodAsync()`` is rather an expression.


Document Details

Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.

BillWagner commented 4 years ago

Thanks for writing this @mpostol This could be explained better.

The point is that await can be either an expression or a statement, depending on its operand. When the operand is a Task, await is parsed as a statement: there is no result. When the operand is a Task<T>, await is parsed as an expression, and it's result is of type T.

I've added this to our backlog to update.

pkulikov commented 4 years ago

@BillWagner I think @mpostol refers to declaration statement T result =.... I think any expression may be at right

mpostol commented 4 years ago

To make sure the C# Language Specification must be revisited and referred to. Sec. 1.4 and 1.5 provides a detailed description. Anyway if we have x=\<something> we have an assignment statement. The mentioned section numbers could change because I have noticed that my specification is very old and I cannot find a new one right now.