Skip to content

[Version 9.0] Feature support for Static anonymous functions #1461

Open
BillWagner wants to merge 4 commits intodraft-v9from
v9-static-anonymous-functions
Open

[Version 9.0] Feature support for Static anonymous functions #1461
BillWagner wants to merge 4 commits intodraft-v9from
v9-static-anonymous-functions

Conversation

@BillWagner
Copy link
Member

@BillWagner BillWagner commented Nov 11, 2025

This pulls in all the commits from #988

There is one conversation on #988 that hasn't been addressed yet:

Add support for static anonymous functions

Add support for static anonymous functions

Add support for static anonymous functions
@BillWagner BillWagner force-pushed the v9-static-anonymous-functions branch from 7133dbb to 69a8d66 Compare November 11, 2025 18:31
@RexJaeschke RexJaeschke added this to the C# 9.0 milestone Nov 11, 2025
@RexJaeschke RexJaeschke added Review: pending Proposal is available for review type: feature This issue describes a new feature labels Nov 11, 2025
@BillWagner BillWagner self-assigned this Jan 16, 2026
Update some language for normative reference.

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.
Copy link
Member Author

Choose a reason for hiding this comment

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

The unresolved comment #988 (comment) is regarding delegate equality for static anonymous functions. This PR doesn't state that static anonymous functions are equal (or the same instance). Roslyn doesn't guarantee that equality.

As such, the standard is fine. (An implementation could do either, as there's no requirement.) Do we want a note that clarifies this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... without this, an implementation could reuse a delegate for a static anonymous function, but not reuse a delegate for a non-static one... but then removing the static modifier does change the meaning of the program. I'd be tempted to remove this line, or caveat it somewhat.

Copy link
Member Author

Choose a reason for hiding this comment

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

Converted to a note.

@BillWagner BillWagner marked this pull request as ready for review January 26, 2026 16:47
@BillWagner BillWagner added the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Jan 26, 2026
@BillWagner
Copy link
Member Author

BillWagner commented Jan 26, 2026

@jskeet This is ready for first review at our next committee meeting.

Copy link
Contributor

@jskeet jskeet left a comment

Choose a reason for hiding this comment

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

Seems mostly fine.


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.
Copy link
Contributor

Choose a reason for hiding this comment

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

Hmmm... without this, an implementation could reuse a delegate for a static anonymous function, but not reuse a delegate for a non-static one... but then removing the static modifier does change the meaning of the program. I'd be tempted to remove this line, or caveat it somewhat.

Respond to the current feedback.

In addition, note that `nameof` arguments and can be used in static local functions and static anonymous functions.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meeting: discuss This issue should be discussed at the next TC49-TG2 meeting Review: pending Proposal is available for review type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants