Skip to content

Test plan for allowing default literal in deconstruction #25559

Open
@jcouv

Description

(int i, string j) = default; // error CS8131: Deconstruct assignment requires an expression with a type on the right-hand-side.
(int i, string j) = (default, default); // OK

This is probably a minor language change (ie. needs to be confirmed with LDM), but I think it would make sense to allow (and give default the type from the left-hand-side). This would be consistent with default in tuple equality ((1, 2) == default).

From discussion in LDM in September, this should be handled more generally as the RHS being target-typed. This means we can use a switch expression with typeless tuple literals (1, null) and they should get target-typed.

Note: some IDE scenarios may need to be updated as a result (see UseDeconstructionTests.cs after https://github.com/dotnet/roslyn/pull/25282/files and https://github.com/dotnet/roslyn/pull/26140/files are merged)

Specification

  • Specification checked in to csharplang.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions