Skip to content

Test plan for "Primary Constructors" feature #65697

@AlekseyTs

Description

@AlekseyTs

Championed issue: dotnet/csharplang#2691
Speclet: https://github.com/dotnet/csharplang/blob/main/proposals/csharp-12.0/primary-constructors.md
Feature branch: https://github.com/dotnet/roslyn/tree/features/PrimaryConstructors

Compiler

  • language version
  • syntax changes:
    • type Name; for class, struct
    • type Name(...) ... for class, struct
    • type Name(...) : Base(...) ... for class
    • error for type Name(...) : Interface(...) ...
    • error for type Name : Base(...) ...
  • public primary constructor emitted
  • declared constructors must call primary constructor
  • error for declared constructor with matching signature
  • error for primary constructor on multiple partial declarations
  • parameters:
  • attributes on parameters:
    • with no target modifier; with param: target; with other target (disallowed)
    • [CallerMemberName]
    • synthesized attributes: NativeIntegerAttribute, DynamicAttribute, TupleElementNames (see ParameterCapturing_*_SynthesizedAttributes)
  • parameter capturing in class, [readonly] struct, [readonly] ref struct (see ParameterCapturing_*)
  • parameter referenced in:
    • instance methods and property or event accessors (capturing)
    • instance field and property initializers (not capturing)
    • static members (error)
    • const field (error)
    • other constructor (error)
    • this(x) or base(x) initializer (error)
    • : Base(x) initializer (not capturing)
    • lambdas (capturing based on containing context)
    • local function (capturing based on containing member)
    • static lambdas and local functions (error if captured)
    • partial method
  • parameter referenced in:
    • is x
    • x()
    • @x (see ParameterCapturing_011_EscapedIdentifier)
    • nameof(x)
    • lock (x) (see ParameterCapturing_098_Lock)
    • using (x) (see ParameterCapturing_099_Using)
    • x switch { ... } (see ParameterCapturing_099_MultiplePathsToNode_SwitchDispatch_02)
    • deconstruction (see ParameterCapturing_103_Deconstruction)
    • &x (see *AddressOf*)
    • x.F fixed size field (see ParameterCapturing_*FixedSizeBuffer)
    • Color Color (see ParameterCapturing_*_ColorColor_*)
  • error capturing ref, in, out, or ref struct parameters (see IllegalCapturingDueToRefness_*)
  • name shadowing (see ParameterScope) from:
  • definite assignment (see DefiniteAssignment_*)
    • out parameters must be assigned
    • use of out parameters before assignment
    • warning for parameters that are not read
  • dynamic dispatch not allowed for : Base(@dynamic) initializer (see BaseArguments_10)
  • (Add Primary Constructor tests for some scenarios from Test Plan #70056) order of evaluation: field initializers, : Base()
  • Semantic model:
    • primary constructor symbol available from containing type
    • GetDeclaredSymbol()
    • GetSymbolInfo()
    • GetSpeculativeSymbolInfo(), GetSpeculativeTypeInfo()
  • LookupSymbols and LookupNames for parameters
    • in initializers
    • in : Base(x, y)
    • in attributes
    • in members (see ParameterScope)
  • analyzer events:
    • syntax events for primary constructor parameters
    • syntax events for : Base(x, y) arguments
    • symbol events for primary constructor parameters
    • IOperation events for synthesized constructor bodies, parameters, default values
  • XML doc comments:
    • param on containing type and members
    • paramref on containing type and members
    • across partial declarations
  • capturing managed parameter makes struct managed (see ParameterCapturing_056_CapturingOfAManagedParameterMakesStructManaged)
  • struct cycles from capture (see ParameterCapturing_*_Cycle)
  • synthesized constructor not allowed on [ComImport] types
  • parameters (captured or not) referenced in lambda (see *ParameterUsedInLambda_InPrimaryConstructor)
  • warning for captured parameter passed to base constructor (see ParameterCapturing_*CapturedAndPassedToBase*)
  • nullable analysis (see ParameterCapturing_*NullableAnalysis*)
  • parameters are readonly in readonly struct (see ParameterCapturing_*_ReadonlyContext)
  • parameter assignment in readonly struct or readonly method (see ParameterCapturing_*_ReadonlyContext)
  • ref safety analysis of parameter references (see ParameterCapturing_145_ReturnByRef, etc.)
  • (Add "Primary Constructors" to Compiler Test Plan.md #70050) add feature to Compiler Test Plan.md
  • (Add Primary Constructor tests for some scenarios from Test Plan #70056) order of emitted fields with/without explicit fields
  • (Add Primary Constructor tests for some scenarios from Test Plan #70056) error for primary constructor on static class
  • report unused parameters
  • SyntaxNormalizer (SyntaxNormalizerTests.TestSpacingOnPrimaryConstructor/TestSemicolonBody)
  • (Add Primary Constructor tests for some scenarios from Test Plan #70056) structs fulfilling the unmanaged constraint requires binding all members first

Public API

IDE test pass

  • Language version upgrade
  • Type and paste new constructs
  • Completion
    • Type completion for parameters
    • Parameter name completion
      • In base initializer
      • In field initializer
      • In member body
    • Dotting off of parameter name
      • In base initializer
      • In field initializer
      • In member body
    • Identifier highlighting
      • Prefix matching
      • Full identifier matching
  • Formatting
    • Format command
  • Automatic Brace Completion
    • Parameter list
    • Argument list
  • Indentation (typing Enter in an unfinished statement indents the next line)
    • Parameter list
    • Argument list
  • Go To definition
    • For parameter
    • For constructor
  • Find All References
    • For parameters
    • For constructor
  • Colorization
    • Types in parameter list
    • Parameter names
  • Error Squiggles
  • Rename of parameter
  • Change signature (for constructor)
  • Extract method/local function for code referencing parameter


Filed issues:

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions