Skip to content

Test plan for "target-typed new" #28489

@jcouv

Description

@jcouv

Compiler (general test plan for reference):

  • LangVersion (TestInLocal_LangVersion8
  • arglist (ArgList, covers new(__arglist) and variants)
  • target-typing a nullable type (TestNullableType01, TestNullableType02)
  • as default parameter value (TestInParameterDefaultValue), in params (ArrayTypeInferredFromParams)
  • in attribute argument (InAttributeParameter)
  • struct with a 1-constructor, but no 0-constructor
  • in string interpolation (InStringInterpolation)
  • in await (TestInAwait, no target-type)
  • with explicit cast (TestBadTargetType_Cast)
  • is it possible to have a constant value? (TestInParameterDefaultValue, not a constant)
  • returning in lambda (with single or multiple returns, TestBestType_Lambda), in async lambda (TestInAsyncLambda_01)
  • with unary operators (+new(), ...), equality (1 == new()), compound (x += new()), ternary (x ? y : new() and vice-versa)
  • in using (InUsing01), in nameof() (InNameOf), in typeof() (InTypeOf), in sizeof() (InSizeOf), in foreach (InForeach), in deconstruction (TestDeconstruction, var (x, y) = new();), in switch (InSwitch1), in patterns (InIsOperator), in if (ConditionalOnNew), in while (ConditionalOnNew), in fixed (InFixed), as an expression-statement (TestInStatement, new();), in lock (InLock)
  • invoking a dynamic method (InvocationOnDynamic, no target-type)
  • as initial value for an auto-property (TestInClassInitializer)
  • returning in async method (ReturningFromAsyncMethod)
  • returning from IEnumerable-returning method
  • yielding from iterator method (YieldReturn)
  • assign to var (TestTargetType_Var), to nullable type (TestNullableType1),
  • semantic model (TestAssignmentToClass, TestAssignmentToStruct, TODO currently shows a natural type)
  • type parameter with and without new() and struct constraint (TestTypeParameter, TestTypeParameter_ErrorCases)
  • IOperation
  • new() { 42 } (TestObjectAndCollectionInitializer)
  • test with collection initializer (TestObjectAndCollectionInitializer, new() { 1, 2, 3 })
  • in object initializer (new C() { x = new() }), collection initializer (new C() { new D(1), new D(2), new() }) (TestObjectAndCollectionInitializer)
  • test with enum type (TestTargetType_Enum), array type, pointer type (TestTargetType_Pointer, error), test in anonymous type (TestTargetType_AnonymousType, error), tuple (TestTargetType_TupleType, okay)
  • ref local
  • ref return (RefReturnValue1, RefReturnValue2)
  • in implicitly-typed array (ImplicitlyTypedArray, no target-type)
  • use as L-value (TestAssignment, new() = 1;)
  • update the compiler test plan
    -[ ] test interaction with any C# 8.0 feature that was merged earlier: ??= (TestInNullCoalescingAssignment), async-streams, nullability, Ranges (InRange)

IDE:

Open LDM questions:

Initial PR: #25196
Proposal: https://github.com/dotnet/csharplang/blob/master/proposals/target-typed-new.md
Championed issue (with LDM history): dotnet/csharplang#100

Relates to #37821 (spec issues with target-typing)

Metadata

Metadata

Assignees

Labels

Area-CompilersFeature - Target-Typed New`new (args)` gets the created type inferred from contextFeature RequestTestTest failures in roslyn-CITest-GapDescribes a specific feature or scenario that does not have test coverage

Type

No type

Projects

Status

Done Umbrellas

Relationships

None yet

Development

No branches or pull requests

Issue actions