zls
zls copied to clipboard
Invalid decl literal usage with enums
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
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.