csharpstandard icon indicating copy to clipboard operation
csharpstandard copied to clipboard

11.7.1 Exhaustive list of non-expression-tree lambdas?

Open jskeet opened this issue 9 years ago • 7 comments

12.7.1 contains:

Certain lambda expressions cannot be converted to expression tree types: Even though the conversion exists, it fails at compile-time. This is the case if the lambda expression:

  • Has a block body
  • Contains simple or compound assignment operators
  • Contains a dynamically bound expression
  • Is async

The wording suggests this is an exhaustive list. Is it intended to be? Can expression trees cope with pointer types etc? I thought there were various oddities which couldn't be expressed.

jskeet avatar May 19 '15 19:05 jskeet

Let's definitely discuss this, but we could still decide to punt for now. Options I can think of:

  • Leave it ambiguous
  • Make it explicitly non-exhaustive, possibly stating that it's implementation-specific
  • Work out the exhaustive list

jskeet avatar Jul 26 '16 11:07 jskeet

Expression trees cannot cope with pointer expressions which is not that unexpected. However, they cannot cope with for example named arguments either which is less expected. The list of limitations can be pretty long and will get longer with any new C# version.

marek-safar avatar Jul 26 '16 12:07 marek-safar

Agreed it will get pretty long. I think that leaves the open question of whether we want to try to make it exhaustive and keep it up-to-date. It would be unpleasant for different implementations to get out of sync, admittedly.

jskeet avatar Jul 26 '16 12:07 jskeet

Decided to punt to C# 6, where we would like to have at least a "more definitive" list.

jskeet avatar Sep 29 '16 21:09 jskeet

All comments prior to this one were before we removed section 7. I've updated the title only.

jskeet avatar Mar 26 '18 08:03 jskeet

Seems we have a resolution, produce a "more definitive" list, but that's not a quick fix but this does need resolving. Labeled to match.

Nigel-Ecma avatar Jul 19 '20 19:07 Nigel-Ecma

The current wording no longer suggests that the list is exhaustive, but also makes it sound as though "wrong phase of the moon" would be a possible failure reason:

https://github.com/dotnet/csharpstandard/blob/draft-v7/standard/conversions.md#1073-evaluation-of-lambda-expression-conversions-to-expression-tree-types

SamB avatar Jun 30 '23 19:06 SamB