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

Support C#7 tuples as default values for optional parameters #16921

Closed
fitdev opened this issue Feb 3, 2017 · 7 comments
Closed

Support C#7 tuples as default values for optional parameters #16921

fitdev opened this issue Feb 3, 2017 · 7 comments
Labels
Area-Language Design Discussion Resolution-By Design The behavior reported in the issue matches the current design Resolution-External The behavior lies outside the functionality covered by this repository

Comments

@fitdev
Copy link

fitdev commented Feb 3, 2017

Version Used:
C#7 in VS2017RC3

Steps to Reproduce:
Right now the following code gives a compilation error:

void Foo((int, bool) bar = (3, false))
{    }

Expected Behavior:
It should work as if the type of bar was the primitive type, since both of its constituent parts are clearly compile-time constant: 3 and false

Actual Behavior:

Error CS1736 Default parameter value for 'bar' must be a compile-time constant

@Unknown6656
Copy link

AFAIK the tuple (int, bool) is internally compiled as struct System::ValueTuple<int, bool>, meaning that it is not a "primitive" in C#-terms. For this feature to work, one would need a CLI language change to allow "primitive structs" (meaning structures, which are entirely composed of other "primitive structures", pointers and/or primitive fields).


Maybe one should consider the implementation of constant or native structure values being allowed to be used as optional parameters. Take a look at the following only mildly related issues:
#16095
#15079
#4982
#5474

@AdamSpeight2008
Copy link
Contributor

Optional Parameter require the default value to be a compile-time constant, as it stored in the metadata.

@gafter
Copy link
Member

gafter commented Feb 3, 2017

This appears to be a C# language design proposal. Language design proposals should be opened for discussion on the csharplang mailing list, and if sufficient support is given, it should be submitted as a pull request to add a proposal in markdown at the csharplang repository.

@gafter gafter added Area-External Area-Language Design Discussion Resolution-External The behavior lies outside the functionality covered by this repository and removed Area-External labels Feb 3, 2017
@Unknown6656
Copy link

Oh jesus christ, not that mailing list again...
I am sorry, but the migration to the mailing list is one huge back-step in my opinion.
I know nobody will miss me, but I will not be further contributing to the C# language design, if it means writing and receiving tons of emails......

@Joe4evr
Copy link

Joe4evr commented Feb 4, 2017

@Unknown6656 Sound your voice in #16916

@Unknown6656
Copy link

@Joe4evr : I will -- I just hoped, that @gafter would also see it, if I write it here .....

@jcouv
Copy link
Member

jcouv commented Jul 29, 2017

I'll go ahead and close this language issue. The current compiler behavior is by-design (tuples don't have a constant value, therefore cannot be used a default values for optional parameters).
Feel free to open a language issue for discussion on the csharplang repo. Thanks

@jcouv jcouv closed this as completed Jul 29, 2017
@jcouv jcouv added the Resolution-By Design The behavior reported in the issue matches the current design label Jul 29, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Language Design Discussion Resolution-By Design The behavior reported in the issue matches the current design Resolution-External The behavior lies outside the functionality covered by this repository
Projects
None yet
Development

No branches or pull requests

6 participants