Skip to content

Draft spec for local function attributes #3008

@RikkiGibson

Description

@RikkiGibson

Related to #1888

Attributes

Local function declarations are now permitted to have attributes. Parameters and type parameters on local functions are also allowed to have attributes.

Attributes with a specified meaning when applied to a method, its parameters, or its type parameters will have the same meaning when applied to a local function, its parameters, or its type parameters, respectively.

A local function can be made conditional in the same sense as a conditional method by decorating it with a [ConditionalAttribute]. A conditional local function must also be static.

Extern

The extern modifier is now permitted on local functions. This makes the local function external in the same sense as an external method.

Similarly to an external method, the local-function-body of an external local function must be a semicolon. A semicolon local-function-body is only permitted on an external local function.

An external local function must also be static.

Syntax

The local functions grammar is modified as follows:

local-function-header
    : attributes? local-function-modifiers? return-type identifier type-parameter-list?
        ( formal-parameter-list? ) type-parameter-constraints-clauses
    ;

local-function-modifiers
    : (async | unsafe | static | extern)*
    ;

local-function-body
    : block
    | arrow-expression-body
    | ';'
    ;

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions