-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
solve the grammar ambiguity with enum literals inside array literals and struct literals #2235
Comments
I'd expect that to work too. Enum literals seem to be missing from the grammar - are they supposed to be included? That might make this easier to address. |
Enum literals aren't finished because they are missing from the grammar and documentation: #683 This is invalid syntax:
Correct syntax would be: test "aoeu" {
var enum_instances = [1]@typeOf(.x){.Error};
} Which would give a compile error of However there is a grammar issue here, which is that Related: #208 |
cc @Hejsil I think you might have an opinion on how to resolve this. |
my proposal:
|
@thejoshwolfe I'm assuming by "anonymous array literals" you mean array initializers without the type prefix, right? Like this: const arr: []u8 = {4, 2}; That would be really nice to have when the type can be inferred by the compiler, since you wouldn't have to specify it manually then. This actually sounds like a great solution to me. Off topic: Is there an existing issue about anonymous array literals? I couldn't find any. |
@thejoshwolfe might be a good idea, but i haven't thought much about this. I'm out travelling and will have time to look more into this in a weeks time. |
I'm accepting #2235 (comment) |
A better link might be #685 (comment) |
If we add enum literals with this patch:
then the |
No ambiguity. This was just a bug in the implementation of the parser. You probably want to implement this in your stage 2 parser PR @hryx :) |
'Tis now done |
Accepted Proposal
The new anonymous enum literals are great, but they don't to seem work with arrays. I assume that this is a bug.
Let's take this enum as an example:
Declaring a single variable works just fine:
But an array of MyEnum does not:
Which leads to the following compiler output:
The text was updated successfully, but these errors were encountered: