Skip to content

textDocument/selectionRange panics on invalid variadic function declaration #3206

@hongtaihu

Description

@hongtaihu

Zig Version

0.16.0

ZLS Version

4944862

Client / Code Editor / Extensions

plain zls with debug

Steps to Reproduce and Observed Behavior

1

reduced from https://github.com/ziglang/zig/blob/master/test/cases/compile_errors/invalid_variadic_function.zig

  fn foo(...) void {
  }

2

send a textDocument/selectionRange request

3

stacktrace:

info  ( main ): Starting ZLS      0.16.0 @ '<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zls-0.16.0/zig-out/bin/zls'
info  ( main ): Log File:         <HOME>/.cache/zls/zls.log (debug)
debug (server): Offset Encoding:  'utf-16'
info  (server): added Workspace Folder: file://<REPO_ROOT>/harness/cases/CASE-20260524-005/workspace (2937 files)
thread 28698 panic: attempt to use null value
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zls-0.16.0/src/ast.zig:869:40: 0x19ef4f5 in paramFirstToken (zls.zig)
        tree.firstToken(param.type_expr.?);
                                       ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zls-0.16.0/src/ast.zig:877:40: 0x19ef22f in paramLoc (zls.zig)
    const first_token = paramFirstToken(tree, param, include_doc_comment);
                                       ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zls-0.16.0/src/features/selection_range.zig:57:55: 0x1a7acd8 in generateSelectionRanges (zls.zig)
                        const param_loc = ast.paramLoc(tree, param, true);
                                                      ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zls-0.16.0/src/Server.zig:1581:55: 0x1a79ea3 in selectionRangeHandler (zls.zig)
    return try selection_range.generateSelectionRanges(arena, handle, request.positions, server.offset_encoding);
                                                      ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zls-0.16.0/src/Server.zig:1825:76: 0x1a79870 in sendRequestSync__anon_38682 (zls.zig)
        .@"textDocument/selectionRange" => try server.selectionRangeHandler(arena, params),
                                                                           ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zls-0.16.0/src/Server.zig:1874:58: 0x1343427 in processMessage (zls.zig)
                const result = try server.sendRequestSync(arena, @tagName(method), params);
                                                         ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zls-0.16.0/src/Server.zig:1891:30: 0x133045e in processMessageReportError (zls.zig)
    if (server.processMessage(arena_allocator.allocator(), message)) |json_message| {
                             ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zig-x86_64-linux-0.16.0/lib/std/Io.zig:1245:17: 0x132fe32 in start (std.zig)
                _ = @as(Cancelable!void, @call(.auto, function, args_casted.*)) catch {};
                ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zig-x86_64-linux-0.16.0/lib/std/Io/Threaded.zig:552:22: 0x1303865 in start (std.zig)
            task.func(task.contextPointer());
                     ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zig-x86_64-linux-0.16.0/lib/std/Io/Threaded.zig:1797:29: 0x1301a64 in worker (std.zig)
            runnable.startFn(runnable, &thread, t);
                            ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zig-x86_64-linux-0.16.0/lib/std/Thread.zig:422:13: 0x1301745 in callFn__anon_27002 (std.zig)
            @call(.auto, f, args);
            ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zig-x86_64-linux-0.16.0/lib/std/Thread.zig:1431:30: 0x1301500 in entryFn (std.zig)
                return callFn(f, self.fn_args);
                             ^
<REPO_ROOT>/tmp/zls-bootstrap-0.16.0/zig-x86_64-linux-0.16.0/lib/std/os/linux/x86_64.zig:105:5: 0x1301665 in clone (std.zig)
    asm volatile (

Expected Behavior

It should not crash.

Attach ZLS log output

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions