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

Add support for non capturing lambda expressions #101

Closed
Tracked by #9
adrianoc opened this issue Sep 16, 2021 · 1 comment
Closed
Tracked by #9

Add support for non capturing lambda expressions #101

adrianoc opened this issue Sep 16, 2021 · 1 comment
Labels
enhancement New feature or request

Comments

@adrianoc
Copy link
Owner

adrianoc commented Sep 16, 2021

Support lambda expressions that does not capture any context.

Func<int, int, int> supported =  (a,b) => a + b; // Does not capture any context.
int p;
Func<int, int> unsupported = (a) => a + p; // Captures p

One open question is how to handle unsupported scenario:

  1. Ignore it and inject a comment in the generated code
  2. Throw an exception
  3. Other ?

I am leaning to 1

Reasoning

Non-capturing lambdas can be implemented by adding a private, static method with an expression body exactly as the body of the lambda expression.

For instance, the example above would be equivalent to:

Func<int, int, int> Supported() => Supported_Lambda;

private static Func<int, int, int> Supported_Lambda(int a, int b) =>  a + b; 

- [ ] One potential approach to implement this is to do a pass before we start visiting a class and inject synthetic methods for these lambda expressions (this is similar to the lowering concept in Roslyn).
- [ ] For readability it is interesting to add these synthetic methods in the beginning of the type (this ensures that the Cecilified code is more easy to read since there's no mixed instructions)

@adrianoc adrianoc mentioned this issue Sep 16, 2021
100 tasks
@adrianoc adrianoc changed the title Non capturing lambda expressions Add support for non capturing lambda expressions Sep 16, 2021
@adrianoc adrianoc added enhancement New feature or request help wanted labels Sep 16, 2021
@adrianoc
Copy link
Owner Author

adrianoc commented Sep 25, 2021

  • Ensure capturing lambdas are detected, a warning is emitted and they get ignored
  • Ensure conversions from lambda to any delegate type but Func/Action generates a warning (comment?) explaining it is not supported
  • Consider adding a comment explaining the generated code most likely will not match 100% the one generated by C# compiler

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant