Skip to content

Invalid decl literal usage with enums #2333

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

Open
FnControlOption opened this issue May 25, 2025 · 1 comment
Open

Invalid decl literal usage with enums #2333

FnControlOption opened this issue May 25, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@FnControlOption
Copy link
Contributor

Zig Version

0.15.0-dev.441+c1649d586

ZLS Version

0.15.0-dev.128+dc1f664b

Client / Code Editor / Extensions

No response

Steps to Reproduce and Observed Behavior

Go to Definition works on all three occurrences of .foo in the following code:

const Enum = enum {
    foo,
};

const a: Enum = .foo;

const b: Enum = .foo(); // !!!

fn bar() void {
    const c: Enum = try .foo; // !!!
    _ = c;
}

Technically, the Zig compiler resolves the second .foo as an Enum but gives an error about it not being a function:

/tmp/decl_literal.zig:7:18: error: type 'decl_literal.Enum' not a function
const b: Enum = .foo(); // !!!
                ~^~~

However, the third .foo is not resolved as an Enum at all:

/tmp/decl_literal.zig:10:26: error: expected error union type, found '@Type(.enum_literal)'
    const c: Enum = try .foo; // !!!
                        ~^~~

Expected Behavior

Go to Definition should not work on .foo inside try .foo

Relevant log output

@FnControlOption FnControlOption added the bug Something isn't working label May 25, 2025
@xdBronch
Copy link
Contributor

imo even though the usage is wrong it seems odd to purposefully make this not work, the try is wrong not the .foo. i see it as being similar to other kinds of fault tolerance LSPs do like giving completions on incomplete code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants