Skip to content
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

zls doesn't infer types after 2 layers of usage? #2205

Open
MahdiGMK opened this issue Feb 27, 2025 · 5 comments
Open

zls doesn't infer types after 2 layers of usage? #2205

MahdiGMK opened this issue Feb 27, 2025 · 5 comments
Labels
bug Something isn't working

Comments

@MahdiGMK
Copy link

Zig Version

0.14.0-dev.3367+1cc388d52

ZLS Version

0.14.0-dev.397+30b0da02

Client / Code Editor / Extensions

Zed dev 0.175.2.r93.gd0a0303 d0a0303428bed88da0c3773740a9cd8b39d8910d

Steps to Reproduce and Observed Behavior

I want to implement this wrapper function for bitset types and zls only predicts type information after 1 layer of function call.

pub fn FBS(BS: type) type {
    return struct {
        bs: BS,
        pub fn format(
            self: @This(),
            comptime fmt: []const u8,
            options: std.fmt.FormatOptions,
            writer: anytype,
        ) !void {
            _ = fmt;
            _ = options;
            _ = writer;
            std.debug.print("{}", .{self.bs.count()}); // no type-hint/auto-completion for self.bs
            // ....
        }
    };
}
pub fn fbs(bitset: anytype) FBS(@TypeOf(bitset)) {
    // auto-completion works fine here
    return FBS(@TypeOf(bitset)){ .bs = bitset };
}

Expected Behavior

Ideally zls should be able to infer that self.bs is a bitset.

Relevant log output

@MahdiGMK MahdiGMK added the bug Something isn't working label Feb 27, 2025
@arrufat
Copy link

arrufat commented Mar 3, 2025

No longer having this problem.

@MahdiGMK
Copy link
Author

MahdiGMK commented Mar 3, 2025

how was it fixed?
I'm asking so I can know project's structure better for potential future contributions :)

@arrufat
Copy link

arrufat commented Mar 3, 2025

I think this might have been caused by the changes in the naming of the cache in the Zig build system. After updating Zig and rebuilding ZLS, it was fixed.

@MahdiGMK
Copy link
Author

MahdiGMK commented Mar 3, 2025

I'v updated to following zig:0.14.0-dev.3452+0367d684f , zls:0.14.0-dev.406+336f468c and it still can't recognize types!

@arrufat
Copy link

arrufat commented Mar 3, 2025

Ok, two things then:

  1. can you try after deleting .zig-cache and ~/.cache/zig?
  2. if that doesn't work, it might be because I also updated my dependency (which I control) to use the new stuff in the build.zig.zon. See: bfactory-ai/zignal@10bb0cf

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