Add support for static anonymous functions#988
Add support for static anonymous functions#988RexJaeschke wants to merge 6 commits intodotnet:draft-v9from
Conversation
|
|
||
| A non-`static` local function or non-`static` anonymous function can capture state from an enclosing `static` anonymous function, but cannot capture state outside the enclosing static anonymous function. | ||
|
|
||
| Removing the `static` modifier from an anonymous function in a valid program does not change the meaning of the program. |
There was a problem hiding this comment.
Should static ensure that all delegate instances converted from the same anonymous function shall compare equal? (That would not require any caching of delegate instances.)
using System;
using System.Diagnostics;
class C {
Action G() {
return static () => {};
}
void M() {
Debug.Assert(G() == G());
}
}I think static should not guarantee this equality. IIRC Roslyn generates an instance method even for a static anonymous function because it is more efficient for the calling convention. Then the delegate will refer to some instance, and will compare unequal if it refers to a different instance. Requiring such an implementation to ensure that the same instance is used every time might cost additional interlocked operations for thread safety.
There was a problem hiding this comment.
Maybe a note about this in the specification of delegate equality would be useful though.
|
Closing in favor of #1461 |
No description provided.