Skip to content

langref: incorrect use of the term "enum variant" in enums.zig #13838

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

Closed
perillo opened this issue Dec 9, 2022 · 1 comment · Fixed by #13847
Closed

langref: incorrect use of the term "enum variant" in enums.zig #13838

perillo opened this issue Dec 9, 2022 · 1 comment · Fixed by #13847
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. docs
Milestone

Comments

@perillo
Copy link
Contributor

perillo commented Dec 9, 2022

The doctest enums.zig in the #enum section has this example:

// An enum variant of different types can be switched upon.
const Foo = enum {
    string,
    number,
    none,
};
test "enum variant switch" {
    const p = Foo.number;
    const what_is_it = switch (p) {
        Foo.string => "this is a string",
        Foo.number => "this is a number",
        Foo.none => "this is a none",
    };
    try expect(mem.eql(u8, what_is_it, "this is a number"));
}

However, IMHO, the term enum invariant is used incorrectly; this term can be used in Rust, but not in Zig. Also, the enum fields all have the same type.

NOTE: the term enum invariant is also used in #12186.

@Vexu Vexu added contributor friendly This issue is limited in scope and/or knowledge of Zig internals. docs labels Dec 9, 2022
@Vexu Vexu added this to the 0.11.0 milestone Dec 9, 2022
@gettsu
Copy link
Contributor

gettsu commented Dec 9, 2022

I am looking to address this issue.
I'm thinking to modify

  1. "// An enum variant of different types can be switched upon." to "// Enums can be switched upon"
  2. "test "enum variant switch"" to "tests "enum switch""

I'll submit a pull request if this is okay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
contributor friendly This issue is limited in scope and/or knowledge of Zig internals. docs
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants