-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Labels
Area-CompilersTestTest failures in roslyn-CITest failures in roslyn-CITest-GapDescribes a specific feature or scenario that does not have test coverageDescribes a specific feature or scenario that does not have test coverage
Milestone
Description
Championed issue: dotnet/csharplang#275
Speclet: https://github.com/dotnet/csharplang/blob/master/proposals/static-lambdas.md
Main PR: #39121
Compiler scenarios
- LangVer (
DisallowInNonPreview) - static lambda cannot reference locals, parameters or
this(StaticLambdaCannotCaptureInstanceField,StaticLambdaCannotCaptureParameter,StaticLambdaCannotReferenceBaseand following) - static lambda can reference static fields/methods/properties (
StaticLambdaCanReferenceStaticField,StaticLambdaCanCallStaticMethodand following) - static lambda can reference
constfield/local (StaticLambdaCanReferenceConstFieldand following) - static lambda inside regular lambda (
InstanceLambdaCannotHaveLocalsCapturedByInnerStaticLambda, - regular lambda inside static lambda (still cannot capture outer locals, parameters or
this) (StaticLambdaCanHaveLocalsCapturedByInnerInstanceLambda - similar mixing of static and regular with lambdas and local functions (
StaticLambdaCannotReferenceInstanceLocalFunction,StaticLambdaCanReferenceStaticLocalFunction,StaticLambdaCannotHaveLocalsCapturedByInnerStaticLambda,StaticLambdaCanHaveLocalsCapturedByInnerInstanceLocalFunction): outer and inner, either may be lambda or local function, either may be static or instance, check referencing variables from outer and middle scope. - verify
nameof(can still reference) - can reference type parameters from enclosing method (
default(T)), should be same as local functions - verify with various lambda syntaxes (with/without types)
- test in top-level statements, with
nint, - success cases should be executed (produce an output), verify diagnostics and emit diagnostics
-
static delegate(including parse tree test) - parse tree test for all supported lambdas
- verify accessibility of private members (instance and static)
- capture what metadata we emit (although no guarantee, same IL as non-static lambda to avoid inefficiency)
-
staticshould not interfere with caching (this falls under the "should not effect emit/validity" umbrella) - verify that static lambda can be used in expression tree
- verify semantic model, verify symbol API, (verify
.IsStatic), verify data flow - verify IOperation (
IAnonymousFunction, symbol covers need for API) - Static anonymous funcs as call arguments:
-
M(static ...) -
M(ref static ...) -
M(param: static ...) - Also indexers:
obj[static ...]and variants
-
- test with lambda discard parameters
- test in ternary (with cast on one side, or with target-typing with new feature), ref ternary (error), and switch expression
- review language parser for "is possible lambda" function
- check diagnostic and parse tree on trying to convert a static lambda to a function pointer (review message)
Productivity
-
converting static anonymous function to static local functionThis refactoring does not seem to exist for regular anonymous functions. - make anonymous function 'static' Add "make anonymous function static" code fix #45832
- recommend
statickeyword - verify what captures are displayed (empty set)
- in practice we display whatever is being captured, including things which are an error to capture.
LDM
- confirm
static delegate(current implementation allows)
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
Area-CompilersTestTest failures in roslyn-CITest failures in roslyn-CITest-GapDescribes a specific feature or scenario that does not have test coverageDescribes a specific feature or scenario that does not have test coverage
Type
Projects
Status
Done Umbrellas