Skip to content
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

Test plan for "Default Lambda Parameters" #62485

Closed
68 of 99 tasks
333fred opened this issue Jul 7, 2022 · 1 comment
Closed
68 of 99 tasks

Test plan for "Default Lambda Parameters" #62485

333fred opened this issue Jul 7, 2022 · 1 comment
Assignees
Milestone

Comments

@333fred
Copy link
Member

333fred commented Jul 7, 2022

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
  • arglist with 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
  • unsafe scenarios
    • sizeof
    • int* parameter with null default 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
  • var produces 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 with dynamic parameter type? (Same question for (dynamic d, ref int i) => { }.)
  • Do (T t = default) => { }, (T t = null) => { } share a delegate type when T is 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 Invoke method 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
@dotnet-issue-labeler dotnet-issue-labeler bot added Area-Compilers untriaged Issues and PRs which have not yet been triaged by a lead labels Jul 7, 2022
@jcouv jcouv added this to the 17.4 milestone Jul 8, 2022
@jcouv jcouv removed the untriaged Issues and PRs which have not yet been triaged by a lead label Jul 8, 2022
@adamperlin
Copy link
Contributor

adamperlin commented Jul 18, 2022

A few failure cases that are coming to mind as I'm doing parsing changes that need to be added at a future step:

  • Implicitly typed default parameters won't be allowed
    (x = 7) => x
  • Optional parameters must come after all required parameters (should be same check as for standard delegate/function definitions)
    (int x = 7, int y) => x + y

Warning Cases:

  • Assigning a default to a discard parameter, i.e., (int _, int _ = 10) => ...

@jaredpar jaredpar modified the milestones: 17.4, C# 12.0 Aug 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants