Skip to content

Conversation

@BillWagner
Copy link
Member

@BillWagner BillWagner commented Nov 11, 2025

Update the C# standard for the feature of applying attributes on local functions.

Note that this also includes specifying extern on a static local function.

This contains all commits from #994. Subsequent edits also made.

@BillWagner BillWagner force-pushed the v9-attribute-locations branch from e32a191 to 4184054 Compare November 11, 2025 20:15
@RexJaeschke RexJaeschke added this to the C# 9.0 milestone Nov 12, 2025
@RexJaeschke RexJaeschke added type: feature This issue describes a new feature Review: pending Proposal is available for review labels Nov 12, 2025
@BillWagner BillWagner self-assigned this Dec 2, 2025
@BillWagner BillWagner force-pushed the v9-attribute-locations branch from 0fc9ff9 to 8b61c71 Compare January 6, 2026 18:20
@BillWagner BillWagner marked this pull request as ready for review January 6, 2026 18:23
@BillWagner BillWagner added the meeting: discuss This issue should be discussed at the next TC49-TG2 meeting label Jan 6, 2026
@BillWagner
Copy link
Member Author

I reviewed the existing edits, made a couple small wording changes.

This is ready for committee review for V9.

For invocations that occur within declarations of instance constructors, static constructors, finalizers and operators the member name used is implementation-dependent.
For an invocation that occurs within a local function, the name of the member method that calls that local function is used. Consider the following: if member method `M` calls local function `F1`, which in turn calls local function `F2`, and `F2` has a parameter marked with this attribute, the method name passed to `F2` is `M`, because a local function is *not* a function member!
Copy link
Contributor

Choose a reason for hiding this comment

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

We should separate out the normative and informative here (and remove the exclamation mark preferrably...) Showing this as actual example code would be useful too.

Copy link
Contributor

Choose a reason for hiding this comment

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

Agreed! My original PR (#994) had a version of this text in an example, but that appears to have been lost. I'll work with Bill to restore it.

Copy link
Contributor

Choose a reason for hiding this comment

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

This is resolved by PR #1548.

A static local function may be made conditional in the same sense as a conditional method ([§23.5.3.2](attributes.md#23532-conditional-methods)).
A compile time error ocurrs if a non-static local function is made conditional.
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm interested in why this is the case - and maybe readers would be too?

#### 23.5.3.1 General
The attribute `Conditional` enables the definition of ***conditional method***s and ***conditional attribute class***es.
The attribute `Conditional` enables the definition of ***conditional methods***, ***conditional local function***s, and ***conditional attribute class***es.
Copy link
Contributor

Choose a reason for hiding this comment

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

Since the original style continues to be followed with the last two items:

Suggested change
The attribute `Conditional` enables the definition of ***conditional methods***, ***conditional local function***s, and ***conditional attribute class***es.
The attribute `Conditional` enables the definition of ***conditional method***s, ***conditional local function***s, and ***conditional attribute class***es.

A static local function may be made conditional in the same sense as a conditional method ([§23.5.3.2](attributes.md#23532-conditional-methods)).
A compile time error ocurrs if a non-static local function is made conditional.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
A compile time error ocurrs if a non-static local function is made conditional.
A compile time error occurs if a non-static local function is made conditional.

For invocations that occur within declarations of instance constructors, static constructors, finalizers and operators the member name used is implementation-dependent.
For an invocation that occurs within a local function, the name of the member method that calls that local function is used. Consider the following: if member method `M` calls local function `F1`, which in turn calls local function `F2`, and `F2` has a parameter marked with this attribute, the method name passed to `F2` is `M`, because a local function is *not* a function member!
Copy link
Contributor

Choose a reason for hiding this comment

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

Lambdas and anonymous methods are in the same boat as local functions.

RexJaeschke and others added 5 commits January 16, 2026 11:11
Add support for attributes and extern on local functions

fix md formatting
This is now ready for committee review.
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.

5 participants