-
Notifications
You must be signed in to change notification settings - Fork 97
[Version 10.0] Feature support for lambda improvements #1566
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
RexJaeschke
wants to merge
9
commits into
draft-v10
Choose a base branch
from
v10-lambda-improvements
base: draft-v10
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
76e5c16
support lambda improvements
RexJaeschke 8ffd488
support lambda improvements
RexJaeschke fc10867
support lambda improvements
RexJaeschke de0566d
support lambda improvements
RexJaeschke 2754510
fix test example name
RexJaeschke 5d279d3
fix formatting
RexJaeschke 436ec73
fix formatting
RexJaeschke 3bf7c8d
Address open comments in PR
BillWagner 19b95d9
Add omissions from this PR
BillWagner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -63,6 +63,7 @@ | |
| - Implicit tuple conversions ([§10.2.13](conversions.md#10213-implicit-tuple-conversions)) | ||
| - Default literal conversions ([§10.2.16](conversions.md#10216-default-literal-conversions)) | ||
| - Implicit throw conversions ([§10.2.17](conversions.md#10217-implicit-throw-conversions)) | ||
| - Anonymous function type conversions (§anon-func-type-conversion) | ||
|
|
||
| Implicit conversions can occur in a variety of situations, including function member invocations ([§12.6.6](expressions.md#1266-function-member-invocation)), cast expressions ([§12.9.8](expressions.md#1298-cast-expressions)), and assignments ([§12.24](expressions.md#1224-assignment-operators)). | ||
|
|
||
|
|
@@ -385,7 +386,7 @@ | |
|
|
||
| ### 10.2.15 Anonymous function conversions and method group conversions | ||
|
|
||
| Anonymous functions and method groups do not have types in and of themselves, but they may be implicitly converted to delegate types. Additionally, some lambda expressions may be implicitly converted to expression tree types. Anonymous function conversions are described in more detail in [§10.7](conversions.md#107-anonymous-function-conversions) and method group conversions in [§10.8](conversions.md#108-method-group-conversions). | ||
| Anonymous functions and method groups do not have types in and of themselves, but they may have a natural type (§anon-func-type). They may be implicitly converted to delegate types. Additionally, some lambda expressions may be implicitly converted to expression tree types. Anonymous function conversions are described in more detail in [§10.7](conversions.md#107-anonymous-function-conversions) and method group conversions in [§10.8](conversions.md#108-method-group-conversions). | ||
|
|
||
| ### 10.2.16 Default literal conversions | ||
|
|
||
|
|
@@ -428,6 +429,46 @@ | |
| 1. for which a common type exists, but one of the expressions `e1` or `e2` has no implicit conversion to that type | ||
|
|
||
| an implicit ***conditional expression conversion*** exists that permits an implicit conversion from *conditional_expression* to any type `T` for which there is a conversion-from-expression from `e1` to `T` and also from `e2` to `T`. It is an error if *conditional_expression* neither has a common type between `e1` and `e2` nor is subject to a conditional expression conversion. | ||
| ### §anon-func-type-conversion Anonymous function type conversion | ||
|
Check failure on line 432 in standard/conversions.md
|
||
|
|
||
| The following conversions are permitted from an anonymous function type `F`(§anon-func-type): | ||
|
|
||
| - To an anonymous function type `G` if the parameters and return types of `F` are variance-convertible to the parameters and return type of `G`. | ||
| - To `System.Delegate` or its base classes or interfaces. | ||
| - To `System.Linq.Expressions.Expression` or `System.Linq.Expressions.LambdaExpression`. | ||
|
|
||
| There are no conversions to an anonymous function type from a type other than an anonymous function type. | ||
|
|
||
| A conversion to `System.Delegate` or its base classes or interfaces realizes the anonymous function or method group as an instance of an appropriate delegate type. | ||
|
|
||
| A conversion to `System.Linq.Expressions.Expression<TDelegate>` or its base classes realizes the anonymous function or method group as an expression tree with an appropriate delegate type. | ||
|
|
||
| > *Example*: | ||
| > | ||
| > <!-- Example: {template:"standalone-console", name: "AnonFuncTypeConv1", ignoredWarnings:["CS8974"]} --> | ||
| > ```csharp | ||
| > Delegate d = delegate (object obj) { }; // Action<object> | ||
| > Expression e = () => ""; // Expression<Func<string>> | ||
| > object o = "".Clone; // Func<object> | ||
| > ``` | ||
| > | ||
| > *end example* | ||
|
|
||
| Anonymous function type conversions are not implicit or explicit standard conversions and are not considered when determining whether a user-defined conversion operator is applicable to an anonymous function or method group. | ||
|
|
||
| Although an implicit conversion to `object` is permitted, a warning shall be issued, as this may have been unintentional. | ||
|
|
||
| > *Example*: | ||
| > | ||
| > <!-- Example: {template:"standalone-console", name: "AnonFuncTypeConv2", ignoredWarnings:["CS8974"]} --> | ||
| > ```csharp | ||
| > Random r = new Random(); | ||
| > object obj; | ||
| > obj = r.NextDouble; // warning: was this intentional? | ||
| > obj = (object)r.NextDouble; // ok | ||
| > ``` | ||
| > | ||
| > *end example* | ||
|
|
||
| ## 10.3 Explicit conversions | ||
|
|
||
|
|
@@ -910,6 +951,7 @@ | |
| - If `F` does not contain an *anonymous_function_signature*, then `D` may have zero or more parameters of any type, as long as no parameter of `D` is an output parameter. | ||
| - If `F` has an explicitly typed parameter list, each parameter in `D` has the same modifiers as the corresponding parameter in `F` and an identity conversion exists between the corresponding parameter in `F`. | ||
| - If `F` has an implicitly typed parameter list, `D` has no reference or output parameters. | ||
| - If `F` has an explicit return type, an identity conversion shall exist from the return type of `F` to the return type of `D`. | ||
| - If the body of `F` is an expression, and *either* `D` has a void return type *or* `F` is async and `D` has a `«TaskType»` return type ([§15.14.1](classes.md#15141-general)), then when each parameter of `F` is given the type of the corresponding parameter in `D`, the body of `F` is a valid expression (w.r.t [§12](expressions.md#12-expressions)) that would be permitted as a *statement_expression* ([§13.7](statements.md#137-expression-statements)). | ||
| - If the body of `F` is a block, and *either* `D` has a void return type *or* `F` is async and `D` has a `«TaskType»` return type , then when each parameter of `F` is given the type of the corresponding parameter in `D`, the body of `F` is a valid block (w.r.t [§13.3](statements.md#133-blocks)) in which no `return` statement specifies an expression. | ||
| - If the body of `F` is an expression, and *either* `F` is non-async and `D` has a non-`void` return type `T`, *or* `F` is async and `D` has a `«TaskType»<T>` return type ([§15.14.1](classes.md#15141-general)), then when each parameter of `F` is given the type of the corresponding parameter in `D`, the body of `F` is a valid expression (w.r.t [§12](expressions.md#12-expressions)) that is implicitly convertible to `T`. | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The MS proposal mentions
System.MulticastDelegate. However, as we don’t have that type in our spec, I replaced all such mentions withSystem.Delegate.