{"action":"created","issue":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/5402","labels_url":"https://api.github.com/repos/dotnet/roslyn/issues/5402/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/roslyn/issues/5402/comments","events_url":"https://api.github.com/repos/dotnet/roslyn/issues/5402/events","html_url":"https://github.com/dotnet/roslyn/issues/5402","id":107828001,"number":5402,"title":"Proposal: Expression Alternative for Statements","user":{"login":"alrz","id":3105979,"avatar_url":"https://avatars.githubusercontent.com/u/3105979?v=3","gravatar_id":"","url":"https://api.github.com/users/alrz","html_url":"https://github.com/alrz","followers_url":"https://api.github.com/users/alrz/followers","following_url":"https://api.github.com/users/alrz/following{/other_user}","gists_url":"https://api.github.com/users/alrz/gists{/gist_id}","starred_url":"https://api.github.com/users/alrz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alrz/subscriptions","organizations_url":"https://api.github.com/users/alrz/orgs","repos_url":"https://api.github.com/users/alrz/repos","events_url":"https://api.github.com/users/alrz/events{/privacy}","received_events_url":"https://api.github.com/users/alrz/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Area-Language%20Design","name":"Area-Language Design","color":"5319e7"},{"url":"https://api.github.com/repos/dotnet/roslyn/labels/Discussion","name":"Discussion","color":"fbca04"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":29,"created_at":"2015-09-23T00:10:45Z","updated_at":"2015-10-15T00:32:30Z","closed_at":null,"body":"Following the proposals #254, #3718, #5154, #5143 and others, it would be a good idea to have an expression alternative for other constructs as well.\r\n### Syntax\r\n>*switch-expression:*\r\n&emsp;`switch` `(` *expression* `)` `:` *switch-expression-block*\r\n\r\n>*switch-expression-block:*\r\n&emsp;`{` *switch-expression-sections* `}`\r\n\r\nAt least one *switch-expression-section* is required.\r\n>*switch-expression-sections:*\r\n&emsp;*switch-expression-section*\r\n&emsp;*switch-expression-sections* *switch-expression-section*\r\n\r\n>*switch-expression-section:*\r\n&emsp;*switch-expression-labels* *expression*\r\n\r\n>*switch-expression-labels:*\r\n&emsp;*switch-expression-label*\r\n&emsp;*switch-expression-labels* *switch-expression-label*\r\n\r\nAs in *switch-statement*, there can be multiple *switch-expression-labels*. They would behave like a *disjunctive-pattern*.\r\n>*switch-expression-label:*\r\n&emsp;`case` *pattern* *case-guard*<sub>opt</sub> `:`\r\n\r\n`switch` expression follows `match` rules and there would be no `default` case; ergo it must be complete.\r\n\r\n>*conjunctive-pattern:*\r\n&emsp;*pattern* `and` *pattern*\r\n\r\n>*disjunctive-pattern:*\r\n&emsp;*pattern* `or` *pattern*\r\n\r\n\r\nIn a *disjunctive-pattern*, the pattern input is matched against the first pattern. If that fails, the pattern input is matched against the second pattern. Both patterns must bind the same set of variables with the same types.\r\n \r\n>*if-expression:*\r\n&emsp;`if` `(` *boolean-expression* `)` `:` *expression*\r\n\r\nNote that *if-expression* cannot return and `else` expression seems redundant because of the existing ternary operator.\r\n\r\n>*try-expression:*\r\n&emsp;`try` `:` *expression* *expression-catch-clause*\r\n\r\n>*expression-catch-clause:*\r\n&emsp;`catch` `:` *expression*\r\n&emsp;`catch` `(` *class-type* *identifier*<sub>opt</sub> `)` `:` *expression*\r\n\r\nI omitted syntax for the `finally` and multiple `catch` clauses for brevity. However, I think they make code unreadable and shouldn't be allowed in expressions.\r\n\r\n>*iterator-expression:*\r\n&emsp;*foreach-expression*\r\n&emsp;*for-expression*\r\n&emsp;*while-expression*\r\n&emsp;*do-expression*\r\n\r\n>*foreach-expression:*\r\n&emsp;`foreach` `(` *local-variable-type* *identifier* `in` *expression* `)` `:` *expression*\r\n\r\n>*for-expression:*\r\n&emsp;`for`   `(`   *for-initializer*<sub>opt</sub>   `;`   *for-condition*<sub>opt</sub>`;`   *for-iterator*<sub>opt</sub>`)` `:`  *expression*\r\n\r\n>*while-expression:*\r\n&emsp;`while`   `(`   *boolean-expression*   `)` `:` *expression*\r\n\r\n>*do-expression:*\r\n&emsp;`do` `:` *expression*   `while`   `(`   *boolean-expression*   `)`\r\n\r\nNote that *iterator-expression* cannot return values.\r\n\r\n>*using-expression:*\r\n&emsp;`using`   `(`    *resource-acquisition*   `)` `:` *expression*\r\n\r\nAdditional syntaxes to be used with statement expressions including:\r\n>*anonymous-method-expression:*\r\n&emsp;...\r\n&emsp;`delegate` `=>` *expression*\r\n\r\n>*accessor-body:*\r\n&emsp;...\r\n&emsp;`=>` *expression* `;`\r\n\r\nSome of the general *expressions* mentioned above should be narrowed to prevent polluted code."},"comment":{"url":"https://api.github.com/repos/dotnet/roslyn/issues/comments/148240912","html_url":"https://github.com/dotnet/roslyn/issues/5402#issuecomment-148240912","issue_url":"https://api.github.com/repos/dotnet/roslyn/issues/5402","id":148240912,"user":{"login":"alrz","id":3105979,"avatar_url":"https://avatars.githubusercontent.com/u/3105979?v=3","gravatar_id":"","url":"https://api.github.com/users/alrz","html_url":"https://github.com/alrz","followers_url":"https://api.github.com/users/alrz/followers","following_url":"https://api.github.com/users/alrz/following{/other_user}","gists_url":"https://api.github.com/users/alrz/gists{/gist_id}","starred_url":"https://api.github.com/users/alrz/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/alrz/subscriptions","organizations_url":"https://api.github.com/users/alrz/orgs","repos_url":"https://api.github.com/users/alrz/repos","events_url":"https://api.github.com/users/alrz/events{/privacy}","received_events_url":"https://api.github.com/users/alrz/received_events","type":"User","site_admin":false},"created_at":"2015-10-15T00:32:30Z","updated_at":"2015-10-15T00:32:30Z","body":"@gafter Yes, I just figured out. Fixed."}}