Skip to content

Conversation

FnControlOption
Copy link
Contributor

switch case equality builtin identifier
const Foo = enum {
    /// Foo.
    foo,
};

// variable/constant declaration
const a: Foo = .foo;

// if-else expression
const b: Foo = if (true) .foo else .foo;

// for-else expression
const c: Foo = inline for (0..0) |_|
{} else .foo;

// while-else expression
const d: Foo = inline while (false)
{} else .foo;

// function call arguments
const e = bar(.foo, .foo);
fn bar(foo1: Foo, foo2: Foo) [2]Foo {
    return [_]Foo{ foo1, foo2 };
}

// variable assignment
const f: Foo = blk: {
    var foo: Foo = undefined;
    foo = .foo;
    break :blk foo;
};

// binary operand
const g = a == .foo;
const h = .foo != a;

// loop/block break
const i: Foo = inline for (0..1) |_|
{
    break .foo;
};

const j: Foo = blk: inline while (true)
{
    break :blk .foo;
};

const k: Foo = blk: {
    if (true) break :blk .foo;
};

const print = @import("std").debug.print;
pub fn main() void {
    for (.{ a, b, c, d } ++ e ++ .{f}) |foo| print(".{s}, ", .{@tagName(foo)});
    for ([_]bool{ g, h }) |boolean| print("{}, ", .{boolean});
    for ([_]Foo{ i, j, k }) |foo| print(".{s}, ", .{@tagName(foo)});
    print("\n", .{});
}

Todo

  • Understand enum type resolution better
  • Resolve type of enum value as the enum itself
  • Investigate why hovering over .@"utf-32" only highlights either utf or 32 but not utf-32 as a whole

@leecannon leecannon merged commit 8545e5f into zigtools:master Jul 7, 2023
@FnControlOption FnControlOption deleted the enum-literal branch July 7, 2023 18:40
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 this pull request may close these issues.

2 participants