csharplang/meetings/2022/LDM-2022-07-13.md

2.2 KiB

C# Language Design Meeting for July 13th, 2022

Agenda

  1. Lambda default parameters

Quote of the Day

  • "We love to point out failures, it's what we do"

Discussion

Lambda default parameters

https://github.com/dotnet/csharplang/pull/6274
https://github.com/dotnet/csharplang/issues/6051

Today, we reviewed the draft specification for default lambda parameters. There are two main parts of this proposal we need to consider:

  1. The actual changes to lambdas themselves. These are relatively straightforward, with only a few nuanced sections we need to consider.
  2. Changing the natural type of method groups. This is more nuanced, as it will be a breaking change from C# 10.

For the first point, we had relatively few pieces of feedback. We think that we should indeed error when the default parameter value of an argument differs from the target type. For example, this should be an error:

delegate void D(int i = 0);
D d = (int i = 1) => {}; // Error: default parameter values differ.

The one case that we think should be acceptable is when the lambda does not specify a default parameter value at all. This is an important backcompat case as it as worked since lambdas were introduced, as well as being user convenience.

delegate void D(int i = 0);
D d1 = i => {}; // Fine: no value specified
D d2 = (int i) => {}; // Fine: no value specified

For the second part, we think we need a more detailed understanding of where the breaks can occur before we decide for sure that we will accept the break. We know from C# 10 how subtle and painful breaks here can be. While they would be more limited in scope, and we think that it would only breaks since C# 10, not since lambdas were introduced, we want to understand the space more before committing.

Finally, we briefly considered whether we should support params parameters as well. We think they're interesting, but didn't make a final decision today.

Conclusion

The lambda rules themselves are accepted, with the error exception for lambdas that don't specify default parameters being converted to a type that does have them. We will get a better understanding on method groups before making a decision.