Skip to content

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

Draft
BillWagner wants to merge 6 commits into
draft-v9from
v9-static-anonymous-functions
Draft

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

Conversation

@BillWagner

@BillWagner BillWagner commented Nov 11, 2025

Copy link
Copy Markdown
Member

This pulls in all the commits from #988

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

@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
Comment thread standard/expressions.md Outdated

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

BillWagner commented Jan 26, 2026

Copy link
Copy Markdown
Member Author

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

@jskeet jskeet left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Seems mostly fine.

Comment thread standard/expressions.md Outdated

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
Copy Markdown
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.

Comment thread standard/expressions.md
Comment thread standard/expressions.md Outdated
@BillWagner BillWagner removed the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Mar 11, 2026
@BillWagner
BillWagner force-pushed the v9-static-anonymous-functions branch from f8a205b to 1948550 Compare April 10, 2026 18:47
BillWagner added a commit that referenced this pull request Apr 10, 2026
@RexJaeschke
RexJaeschke marked this pull request as draft May 5, 2026 14:53
@BillWagner
BillWagner force-pushed the v9-static-anonymous-functions branch from 99625f9 to d0035cc Compare May 12, 2026 20:23
RexJaeschke and others added 6 commits June 24, 2026 13:44
Add support for static anonymous functions

Add support for static anonymous functions

Add support for static anonymous functions
Update some language for normative reference.
Respond to the current feedback.

In addition, note that `nameof` arguments and can be used in static local functions and static anonymous functions.
…hange

Update gruntree references for part-I and part-L to wrap 'async' in
the new anonymous_function_modifier node. Update RightShift stderr
reference to include 'static' in the expected token list.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Update part-I and part-L tree reference files to wrap 'async' in
anonymous_function_modifier nodes, matching the grammar change for
static anonymous functions.

- part-I: lambda_expression now uses (anonymous_function_modifier async)
- part-L: anonymous_method_expression now uses (anonymous_function_modifier async)

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@BillWagner
BillWagner force-pushed the v9-static-anonymous-functions branch from d0035cc to e5d7333 Compare June 24, 2026 17:44
@BillWagner

Copy link
Copy Markdown
Member Author

An earlier version of this feature is already present on alpha-v9 from a prior meeting. Edits made to this PR since then are not yet on alpha-v9; they will land at the next propagation. If you need them on alpha-v9 sooner, please open a separate PR targeting alpha-v9.
Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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