-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Closed
Description
Championed issue: dotnet/csharplang#6051
Spec: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-12.0/lambda-method-group-defaults.md
General
- Lang Version
- Sync with partner teams on method group breaking change
- Missing constant value types
- Compile BCL
- Compile VS
- GetSymbolInfo returns delegate type with default parameters
- GetConstantValue on default parameter value
- IOperation symbols reflect default values
Syntax
- Parse parameter initializers
- Delegate syntax
- Lambda syntax
- Missing expression after
=- Delegate syntax
- Lambda syntax
- No parentheses around the parameter for lambda
- Missing parameter type
- Delegate syntax
- Lambda syntax
- With attributes
-
arglistwith initializer -
(int i = > 0) => { }
Semantics
- Valid constant values
- sbyte
- byte
- short
- ushort
- int
- uint
- long
- ulong
- nint
- nuint
- char
- float
- double
- decimal
- bool
- enum
- string
- null reference
- Target-typed constant conversion
- Valid literal conversion
- Valid non-literal conversion
- Non-constant expression
- Non-constant non-literal
- Non-constant literal (u8 string, interpolated string)
- Interpolated string handler conversion
- Invalid constant conversion
- Recursive parameter reference
- Parameter before the reference
- Parameter after the reference
- Constant value from the same scope
- Defined before the lambda
- Defined after the lambda
- Well-known attributes that affect constant parameters
- DefaultValueAttribute
- CallerInfoX
- Params
-
unsafescenarios-
sizeof -
int*parameter withnulldefault value
-
- Non-default parameters trailing
- Mismatched default parameters between lambda and target delegate type
- Both have different constant values - Error
- Target delegate has constant value, lambda does not - Valid
- Target delegate does not have constant value, lambda does - Error
- Mismatched default parameters between method group and target delegate type
- Both have different constant values - Warning
- Target delegate has constant value, method does not - Valid
- Target delegate does not have constant value, method does - Valid
- Conversion between different delegate types is unaffected
-
varproduces anonymous delegate type with default parameters and does not use Action/Func- Lambda
- Method group
- Nullability analysis
- Discard parameters with defaults.
- Does
(dynamic d = null) => { }create a delegate withdynamicparameter type? (Same question for(dynamic d, ref int i) => { }.) - Do
(T t = default) => { },(T t = null) => { }share a delegate type whenTis appropriately constrained? - MemberSemanticModel should be parented to the correct outer SemanticModel
- symbols for locals declared outside of a lambda referenced inside default value should be reference identical to symbols returned by GetDeclaredSymbol for the locals and for references to the locals outside of the lambda
- binder chain should be shared with member model for the enclosing method body
- step through the code to make sure the correct things happen
- SpeculativeSemanticModel to ensure errors from default parameter values are not added to declaration table
- Expression trees: follow up with LDM on whether it should be allowed
-
new[] { (int i = 1) => { }, (int i = 2) => { } }is there a best common type or an error? - Matching default value to generic type:
delegate D<T>(T t = default); void M<T>(D<T> p) { } M((object o = null) => {});
- NoPIA: can an embedded type leak through to the delegate type? (not specific to default params)
- A parameter with a ref, out or this modifier cannot have a default_argument
- A parameter_array may occur after an optional parameter, but cannot have a default value
Emit
- Emits an anonymous delegate type with default parameters
- Generices non-default parameters where possible
- Shares lambda definitions where default parameters are the same
- Emitted
Invokemethod for the lambda has default parameters
Productivity
- FindAllReferences
- Unused constants in default parameter values
- Parameter default value completion when typing
- Extract local uses
var - Convert to method preserves default values
- EnC: default lambda parameters #69246
Reactions are currently unavailable