-
-
Couldn't load subscription status.
- Fork 3.6k
Closed
Description
Language Feature(s):
- C# 4.0 optional arguments
- C# 4.0 named arguments
- C# 7.2 non-trailing named arguments
These features should be implemented in one go, because they depend on each other.
Affected areas:
- ILAst
- ILInlining
- CallBuilder
1) Optional Arguments:
Optional values can only be: ldnull, ldstr, ldc.*, default.value
- CallBuilder: Remove optional arguments, if overload resolution allows it.
2) Named Arguments:
CallInstruction currently does not distinguish between the argument evaluation order, and the parameter order. The CallInstruction.Arguments collection must be in evaluation order. But we can extend CallInstruction to allow more flexible mapping of arguments to parameters.
- Extend
CallInstruction: Addint[] argumentToParameterMap. For each argument index, this would specify the corresponding parameter index in the method's parameter collection.- The
thisparameter (which isn't present in the method's parameter collection) could be represented as-1. It must remain argument 0. CallInstruction.CheckInvariantshould check that the mapping between arguments and parameters is 1-to-1.- All code that deals with call arguments+parameters will need adjustment!
- The
- Add some ILAst transform that reorders both the call arguments and adjusts the
argumentToParameterMapin order to open up new inlining possibilities (maybe as extension toILInlining? or as a newStatementTransform?) - CallBuilder: use named arguments when argument order differs from parameter order
- When using named arguments, emit
NamedArgumentExpression - Also report the argument names to the resolver.
- When using named arguments, emit
3) Non-trailing Named Arguments:
- Do they change/affect overload resolution rules in any way? (see https://github.com/dotnet/csharplang/blob/master/proposals/csharp-7.2/non-trailing-named-arguments.md)
- Yes: only overloads with matching parameter names are applicable, so adding names can resolve ambiguities.
- But I don't think adding names can change the result of an already-successful overload resolution.
- CallBuilder: Add NamedArgumentExpression for any constants
Related:
- Support for nameof in well-known cases (Exception ctors, CallerMemberNameAttribute)
- CallerMemberNameAttribute: Remove ldstr arguments if optional and value == CurrentMember.Name
Metadata
Metadata
Assignees
Labels
No labels