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: Stackalloc array initializers (15.7) #1286

Open
2 of 5 tasks
jcouv opened this issue Jan 29, 2018 · 2 comments
Open
2 of 5 tasks

Champion: Stackalloc array initializers (15.7) #1286

jcouv opened this issue Jan 29, 2018 · 2 comments
Assignees
Labels
Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification Proposal champion
Milestone

Comments

@jcouv
Copy link
Member

jcouv commented Jan 29, 2018

In addition to the currently allowed syntax (stackalloc int[3]) we should allow stack allocated arrays be created with initialization:

stackalloc int[3] { 1, 2, 3 }
stackalloc int[] { 1, 2, 3 }
stackalloc[] { 1, 2, 3 }

Discussed in LDM in Jan 2018 (link to meeting notes TBD)
Prototype dotnet/roslyn#24249

@jcouv jcouv self-assigned this Jan 29, 2018
@Thaina
Copy link

Thaina commented Jan 30, 2018

Alternatively I think we can have the same mechanism with Tuple extension indexer

I mean if we could have extension indexer we can extend Tuple<T,T,T,T,T,T,T,T> to allow indexing on it

var imitatingarray = (0,1,2,3,4,5,6,7);

imitatingarray[0]; // 0

@jcouv
Copy link
Member Author

jcouv commented Jan 30, 2018

@Thaina The rationale for the proposed design is to match the syntax closely what is already allowed (such as new int[3] { 1, 2, 3 }) except with the keyword stackalloc instead of new so that transition is easier. It is less cognitive load (you don't have to remember two syntaxes and which is allowed when) and also less code churn when adopting stackalloc in an existing codebase.
Although the tuple approach is possible, it breaks away from habit and expectations.

@jcouv jcouv added this to the 7.3 candidate milestone Feb 23, 2018
@jcouv jcouv changed the title Champion: Stackalloc array initializers Champion: Stackalloc array initializers (15.7) Mar 16, 2018
@333fred 333fred added the Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification label Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Implemented Needs ECMA Spec This feature has been implemented in C#, but still needs to be merged into the ECMA specification Proposal champion
Projects
None yet
Development

No branches or pull requests

3 participants