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

Prohibit stackalloc int[3][1] #1232

Open
jskeet opened this issue Dec 11, 2024 · 3 comments · May be fixed by #1237
Open

Prohibit stackalloc int[3][1] #1232

jskeet opened this issue Dec 11, 2024 · 3 comments · May be fixed by #1237
Milestone

Comments

@jskeet
Copy link
Contributor

jskeet commented Dec 11, 2024

In #1211 it looks like stackalloc int[3][1] should be valid by the standard, but Roslyn complains. We've decided it wouldn't do what is probably expected anyway, so it would be better to prohibit it in the standard.

We haven't yet decided on the best approach for this (e.g. in the grammar or as an additional semantic rule in the text).

@gafter
Copy link
Member

gafter commented Dec 11, 2024

Possible strategy: Categorize it as an array creation expression in the grammar.

@gafter gafter added this to the C# 8.0 milestone Dec 11, 2024
@jnm2
Copy link
Contributor

jnm2 commented Dec 12, 2024

Would it help those who come after us to say something explicit, so that people don't have to try to tease apart whether or not things were blocked by design and what the rationale might have been?

gafter added a commit that referenced this issue Dec 15, 2024
@gafter gafter linked a pull request Dec 15, 2024 that will close this issue
@gafter gafter removed their assignment Dec 15, 2024
@gafter
Copy link
Member

gafter commented Dec 15, 2024

@jnm2 Yes, and the proposed solution piggy-backs on such text already in the standard:

Primary expressions are divided between array_creation_expressions and primary_no_array_creation_expressions. Treating array_creation_expression in this way, rather than listing it along with the other simple expression forms, enables the grammar to disallow potentially confusing code such as

object o = new int[3][1];

which would otherwise be interpreted as

object o = (new int[3])[1];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants