Skip to content
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

Update lambda-improvements.md to match language design decisions #5388

Merged
merged 11 commits into from
Nov 9, 2021

Conversation

cston
Copy link
Member

@cston cston commented Nov 6, 2021

Various updates to proposals/csharp-10.0/lambda-improvements.md to match language design decisions and C#10 implementation:

  • Include anonymous methods in function types and conversions (email discussion)
  • Remove direct invocation
  • var cannot be used as an explicit return type (see 2021-06-02)
  • No inferred type for discard assignment
  • Function type conversions are not standard conversions and are ignored for user-defined conversions (email discussion)
  • Update better function member and better conversion from expression (see 2021-09-20)
  • Warning implicitly converting method group to object (see 2021-08-23)
  • Function types are used in a few specific contexts (see 2021-07-26)
  • Moved open issues to separate section
  • Removed design meeting links (moved to championed issue #4934)

```csharp
var fs = new[] { (string s) => s.Length; (string s) => int.Parse(s) } // Func<string, int>[]
```

### `var`
Lambda expressions and method groups with natural types can be used as initializers in `var` declarations.
Anonymous functions and method groups with inferred types can be used as initializers in `var` declarations.
Copy link
Member

@jcouv jcouv Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inferred

"... with function types" would be better.
We have a section on ## Natural (function) type, we didn't talk about "inferred function type" or "inferred type" before in the doc. #Resolved

@@ -210,52 +245,47 @@ var f7 = "".F1; // System.Action
var f8 = F2; // System.Action<string>
```

The type of an anonymous function or method group is not inferred for implicitly-typed discards.
Copy link
Member

@jcouv jcouv Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider: "Function types are not used in assignments to discards" #Resolved

@@ -276,6 +306,19 @@ lambda_parameter
;
```

## Open issues
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Haven't those open issues been resolved already?

Should the _function_type_ be available from the compiler API, in addition to the resulting delegate type?

Currently, the inferred delegate type uses `System.Action<>` or `System.Func<>` when parameter and return types are valid type arguments _and_ there are no more than 16 parameters, and if the expected `Action<>` or `Func<>` type is missing, an error is reported. Instead, should the compiler use `System.Action<>` or `System.Func<>` regardless of arity? And if the expected type is missing, synthesize a delegate type otherwise?

## Design meetings
Copy link
Member

@jcouv jcouv Nov 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider moving this list to the championed issue (easier to update), or only keeping it here and updating it with latest links. #Resolved

@jcouv jcouv self-assigned this Nov 9, 2021
Copy link
Member

@jcouv jcouv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done with review pass (iteration 10)

@cston cston merged commit 87b42f2 into dotnet:main Nov 9, 2021
@cston cston deleted the lambda-updates branch November 9, 2021 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants