Skip to content

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

Merged
jskeet merged 8 commits into
draft-v9from
v9-static-anonymous-functions
Nov 4, 2026
Merged

jskeet merged 8 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 Resolved
Comment thread standard/expressions.md Resolved
@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
@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!

@BillWagner
BillWagner force-pushed the v9-static-anonymous-functions branch from e5d7333 to 65e32a7 Compare July 24, 2026 19:50
@BillWagner
BillWagner force-pushed the v9-static-anonymous-functions branch from 65e32a7 to 846229e Compare September 18, 2026 19:54
RexJaeschke and others added 6 commits October 13, 2026 14:19
Add support for static anonymous functions

Add support for static anonymous functions

Add support for static anonymous functions

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Update some language for normative reference.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
Respond to the current feedback.

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

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
…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>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
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>
Copilot-Session: 21570b74-c6f5-4fc5-ab6d-7546918d6ddb
@BillWagner
BillWagner force-pushed the v9-static-anonymous-functions branch from 846229e to e66307c Compare October 14, 2026 13:56
@BillWagner
BillWagner marked this pull request as ready for review October 22, 2026 18:58
@BillWagner BillWagner added the Review requested: Final approval All comments on the detailed review have been addressed. A final look is requested. label Oct 22, 2026
@BillWagner BillWagner added the meeting: priority Review before meeting. Merge, merge with issues, or reject at the next TC49-TC2 meeting label Oct 22, 2026
@BillWagner

Copy link
Copy Markdown
Member Author

All previous comments have been addressed, and this one is reasonably small. I think it can be merged at the next meeting.

Comment thread standard/expressions.md Resolved
Comment thread standard/expressions.md Resolved
@jskeet

jskeet commented Nov 4, 2026

Copy link
Copy Markdown
Contributor

Will merge on green.

@jskeet
jskeet merged commit 19a1354 into draft-v9 Nov 4, 2026
9 checks passed
@jskeet
jskeet deleted the v9-static-anonymous-functions branch November 4, 2026 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

meeting: priority Review before meeting. Merge, merge with issues, or reject at the next TC49-TC2 meeting Review: pending Proposal is available for review Review requested: Final approval All comments on the detailed review have been addressed. A final look is requested. type: feature This issue describes a new feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants