Skip to content

various incorrect capture by ref ranges #18579

@travisstaloch

Description

@travisstaloch

Zig Version

0.12.0-dev.2158+4f2009de1

Steps to Reproduce and Observed Behavior

I noticed while using zls a few pointer captures which don't account for capturing by reference. All of the following code snippets incorrectly highlight the asterisk instead of the identifier:

    switch (undefined) {
        .a => |*ident| {},
        //     ^ unused capture
        //      ^^^^^ range should be here
    }

    if (undefined) |*foo| {} else |err| {}
    //              ^ unused capture

    while (undefined) |*foo| {} else |err| {}
    //                 ^ unused capture

   // EDITED here, removed incorrect by ref capture

I have a PR in the works which I'll submit soon.

Thanks to @Techatrix for helping me discover some of these in the zls discord. I originally only noticed that the switch pointer capture was off and he helped spot the others.

Expected Behavior

correct ranges for unused captures

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugObserved behavior contradicts documented or intended behaviorfrontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions