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

Champion: allow 'default' in deconstruction #1394

Closed
5 tasks
jcouv opened this issue Mar 17, 2018 · 7 comments
Closed
5 tasks

Champion: allow 'default' in deconstruction #1394

jcouv opened this issue Mar 17, 2018 · 7 comments
Labels
Needs Implementation The specification for this issue has been approved, it needs an implementation Proposal champion
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented Mar 17, 2018

Allow (int i, string s) = default; and (i, s) = default.

  • Proposal added
  • Discussed in LDM (by email so far)
  • Decision in LDM
  • Finalized (done, rejected, inactive)
  • Spec'ed

Initially raised in #1358 (thanks @KnorxThieus)
Prototype in decon-default branch

@AustinBryan
Copy link

This will be super nice to do in constructors:

class MyClass
{
    int foo;
    string bar;
    byte baz

    public MyClass() => (foo, bar, baz) = default;
}

@jnm2
Copy link
Contributor

jnm2 commented Jun 11, 2018

@AustinBryan Those fields are already zero-inited, so what is the purpose of that constructor?

@jcouv jcouv modified the milestones: 8.0 candidate, 8.X candidate Jul 18, 2019
@gafter gafter modified the milestones: 8.X candidate, Any Time Sep 11, 2019
@alrz
Copy link
Member

alrz commented Sep 12, 2019

The use case I had in mind for this is assigning a bunch of out parameters on a failure case,

bool TryGet(out int i, out double d) {
  // ...
  (i, d) = default;
  return false;
}

btw I think this is already implemented by jcouv, why the Any Time milestone?

@jcouv
Copy link
Member Author

jcouv commented Sep 12, 2019

The implementation I have is not quite complete because we've recently implemented more target-typing scenarios (switch expressions in particular). So (i, d) = expr switch { true => (1, null); _ => throw null; }; should work too (ie. giving the tuple in branch a type).

@333fred 333fred added the Needs Implementation The specification for this issue has been approved, it needs an implementation label Oct 15, 2020
@Rekkonnect
Copy link
Contributor

Rekkonnect commented Jul 8, 2022

Taking some time into the code regarding this case, and a side-effect would have to also be matching the individual types of the tuple expression:

(1, default)
(default, "")
(1, null)

should match as (int, string), whereas

(1, default)
(null, "")

should match as (int?, string).

I'm awaiting for a response on whether it's okay to follow this approach in another branch targeting the features/decon-default branch, which could be considered a relevant but different feature.

@Rekkonnect
Copy link
Contributor

@jcouv are there any updates on this moving forward? #1358 is still in the Working Set, and the only scenario that I believe was indeed left is the target typing from switch expressions.

@dotnet dotnet locked and limited conversation to collaborators Nov 19, 2024
@jcouv jcouv removed their assignment Nov 19, 2024
@jcouv
Copy link
Member Author

jcouv commented Nov 19, 2024

Closing as duplicate of #1358

@jcouv jcouv closed this as not planned Won't fix, can't repro, duplicate, stale Nov 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Needs Implementation The specification for this issue has been approved, it needs an implementation Proposal champion
Projects
None yet
Development

No branches or pull requests

8 participants