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

Missing Diagnostics #1659

Closed
XeroOl opened this issue Dec 9, 2023 · 4 comments
Closed

Missing Diagnostics #1659

XeroOl opened this issue Dec 9, 2023 · 4 comments
Labels
enhancement New feature or request

Comments

@XeroOl
Copy link

XeroOl commented Dec 9, 2023

Zig Version

0.11.0

Zig Language Server Version

0.11.0

Steps to Reproduce

Open a file with the contents:

const std = @import("std");

pub fn main() !void {
    std.debug.print("All your {s} are belong to us.\n", .{});
}

Note that zls does not emit any warning or error diagnostic describing any problem.

Then, run zig build, and note that zig build does produce an error describing a problem.

Expected Behavior

I would expect that zls can detect compile errors, because zls uses zig to analyze the code.
More precisely, I would expect one of these two cases:

  1. zls produces no error diagnostics, and zig build compiles the code
  2. zls produces error diagnostics, and zig build fails to compile the code

Actual Behavior

With zls running in my editor, no diagnostic is produced, but zig build fails to build the code.

This is incredibly annoying because it means I have to repeatedly switch between the terminal and the editor, and search for line numbers, instead of being able to just see the problems in my code.

There are many many more reproduction cases where zig build is able to find problems that zls seems oblivious to.

@XeroOl XeroOl added the bug Something isn't working label Dec 9, 2023
@Techatrix
Copy link
Member

ZLS does not use Zig to perform code analysis (semantic analysis to be specific). Integrating semantic analysis into ZLS is a large and complex task. Related issues: #551 #552 ziglang/zig#615

There is a relatively new enable_build_on_save option in ZLS master that allows you to get diagnostics that would are generated by building the project with zig build.

@Techatrix Techatrix added enhancement New feature or request and removed bug Something isn't working labels Dec 10, 2023
@WillLillis
Copy link
Contributor

I was kinda curious why this error wasn't showing up even with enable_build_on_save turned on. It looks like the issue is how the error is reported by the zig compiler. The error diagnostic is published by zls, but it won't show up inline for the file where you're calling std.debug.print.

image

but rather where @compileError() is hit:

image

It looks like any error reported with @compileError will behave this way. I thought that maybe there could be some alternative way of parsing the source location in these cases to work around it, but (unless I'm missing something) the source of the error isn't reported anywhere in the output from zig build (even with -freference-trace.:

❯ zig build -freference-trace                                                                            ⏎
install
└─ install test_zls
   └─ zig build-exe test_zls Debug native 1 errors
/home/lillis/zig/lib/std/fmt.zig:183:13: error: too few arguments
            @compileError("too few arguments");
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
    print__anon_3530: /home/lillis/zig/lib/std/io/Writer.zig:24:26
    print: /home/lillis/zig/lib/std/io.zig:324:47
    dumpCurrentStackTrace: /home/lillis/zig/lib/std/debug.zig:198:19
    unexpectedErrno: /home/lillis/zig/lib/std/posix.zig:7324:18
    raise: /home/lillis/zig/lib/std/posix.zig:716:34
    abort: /home/lillis/zig/lib/std/posix.zig:684:9
    handleSegfaultPosix: /home/lillis/zig/lib/std/debug.zig:2624:10
    attachSegfaultHandler: /home/lillis/zig/lib/std/debug.zig:2558:36
    maybeEnableSegfaultHandler: /home/lillis/zig/lib/std/debug.zig:2535:18
    callMainWithArgs: /home/lillis/zig/lib/std/start.zig:479:14
    posixCallMainAndExit: /home/lillis/zig/lib/std/start.zig:438:20
    _start: /home/lillis/zig/lib/std/start.zig:351:40
error: the following command failed with 1 compilation errors:
/home/lillis/zig/build/stage3/bin/zig build-exe -freference-trace=256 -ODebug -Mroot=/home/lillis/projects/test_zls/src/main.zig --cache-dir /home/lillis/projects/test_zls/.zig-cache --global-cache-dir /home/lillis/.cache/zig --name test_zls --listen=-
Build Summary: 2/5 steps succeeded; 1 failed (disable with --summary none)
install transitive failure
└─ install test_zls transitive failure
   └─ zig build-exe test_zls Debug native 1 errors
error: the following build command failed with exit code 1:
/home/lillis/projects/test_zls/.zig-cache/o/169ef625c4b03d73e3a2b14672ed13c1/build /home/lillis/zig/build/stage3/bin/zig /home/lillis/projects/test_zls /home/lillis/projects/test_zls/.zig-cache /home/lillis/.cache/zig --seed 0x5b844879 -Z977f7c67defdb21c -freference-trace

Maybe it would be worth looking into how something could be changed upstream to include the actual source location for the error? I'd love to look into this but I'm still pretty useless when it comes tot zig internals.

@Techatrix
Copy link
Member

I recall having a conversation with someone about this exact issue. I also had the idea of using the reference trace to report a diagnostic at the call-site of std.debug.print but this bug in Zig made it not implementable. This has been reported in ziglang/zig#19158. There are also a few other issues that track similar issues.

@Techatrix
Copy link
Member

The missing diagnostic issue is tracked by #2017. The bad source location of the error message is tracked by #2018. So I will be closing this issue in favor of those.

@Techatrix Techatrix closed this as not planned Won't fix, can't repro, duplicate, stale Aug 31, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants