Skip to content

Add support for attributes and extern on local functions #994

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 5 commits into
base: draft-v9
Choose a base branch
from
Draft
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Add support for attributes and extern on local functions
  • Loading branch information
RexJaeschke authored Nov 19, 2023
commit a8271dfceb512900e232e7250730508765dbbc84
20 changes: 14 additions & 6 deletions standard/statements.md
Original file line number Diff line number Diff line change
Expand Up @@ -487,36 +487,40 @@ A *local_function_declaration* declares a local function.

```ANTLR
local_function_declaration
: local_function_modifier* return_type local_function_header
: attributes? local_function_modifier* return_type local_function_header
local_function_body
| ref_local_function_modifier* ref_kind ref_return_type
| attributes? ref_local_function_modifier* ref_kind ref_return_type
local_function_header ref_local_function_body
;

local_function_header
: identifier '(' formal_parameter_list? ')'
| identifier type_parameter_list '(' formal_parameter_list? ')'
: identifier parameter_list?
| identifier type_parameter_list parameter_list?
type_parameter_constraints_clause*
;

local_function_modifier
: ref_local_function_modifier
| 'async'
| 'extern'
;

ref_local_function_modifier
: unsafe_modifier // unsafe code support
: 'extern'
| unsafe_modifier // unsafe code support
;

local_function_body
: block
| '=>' null_conditional_invocation_expression ';'
| '=>' expression ';'
| ';'
;

ref_local_function_body
: block
| '=>' 'ref' variable_reference ';'
| ';'
;
```

Expand Down Expand Up @@ -561,7 +565,11 @@ Unless specified otherwise below, the semantics of all grammar elements is the s

The *identifier* of a *local_function_declaration* must be unique in its declared block scope, including any enclosing local variable declaration spaces. One consequence of this is that overloaded *local_function_declaration*s are not allowed.

A *local_function_declaration* may include one `async` ([§15.15](classes.md#1515-async-functions)) modifier and one `unsafe` ([§23.1](unsafe-code.md#231-general)) modifier. If the declaration includes the `async` modifier then the return type shall be `void` or a `«TaskType»` type ([§15.15.1](classes.md#15151-general)). The `unsafe` modifier uses the containing lexical scope. The `async` modifier does not use the containing lexical scope. It is a compile-time error for *type_parameter_list* or *formal_parameter_list* to contain *attributes*.
A *local_function_declaration* may include a set of *attributes* ([§22](attributes.md#22-attributes)), one `async` ([§15.15](classes.md#1515-async-functions)) modifier, one `extern` ([§15.6.8](classes.md#1568-external-methods)) modifier, and one `unsafe` ([§23.1](unsafe-code.md#231-general)) modifier. If the declaration includes the `async` modifier then the return type shall be `void` or a `«TaskType»` type ([§15.15.1](classes.md#15151-general)). The `unsafe` modifier uses the containing lexical scope. The `async` modifier does not use the containing lexical scope.

An external local function shall have the modifier `static`, and its *local_function_body* or *ref_local_function_body* shall be a semicolon.

A *local_function_body* or *ref_local_function_body* shall be a semicolon only for an external local function.

A local function is declared at block scope, and that function may capture variables from the enclosing scopes. It is a compile-time error if a captured variable is read by the body of the local function but is not definitely assigned before each call to the function. The compiler shall determine which variables are definitely assigned on return ([§9.4.4.33](variables.md#94433-rules-for-variables-in-local-functions)).

Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy