-
Notifications
You must be signed in to change notification settings - Fork 1k
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 spec for local function attributes #3008
Comments
For In other words, would the code in #2740 work as is at runtime? |
|
When using DllImport on a local function, it is expected that the EntryPoint defaults to the name of the local function as it appears in source. |
@HaloFour Yeah, you're right, I didn't think of that. @RikkiGibson Good to know. |
In the test plan review for this feature, we came up with a scenario where definite assignment safety could be violated in local functions. using System.Diagnostics;
using System;
class C
{
void M()
{
int x;
local1();
Console.WriteLine(x);
[Conditional("DEBUG")]
void local1()
{
x = 42;
}
}
} In this scenario, We think we can solve this by adding the requirement that a local function with ConditionalAttribute must be static. |
Closing in favor of #1888 (added link to speclet there) |
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 bestatic
.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:
The text was updated successfully, but these errors were encountered: