Skip to content

Conversation

@travisstaloch
Copy link
Contributor

fixes #18579

i've verified that after this change, the following error ranges are correct and point at the identifiers instead of the asterisks

    switch (undefined) {
        .a => |*ident| {},
        //      ^^^^^ unused capture
    }
    if (undefined) |*foo| {} else |err| {}
    //               ^^^ unused capture
    while (undefined) |*foo| {} else |err| {}
    //                  ^^^ unused capture

@travisstaloch
Copy link
Contributor Author

travisstaloch commented Jan 16, 2024

I added back in this line per suggestion by @Techatrix. I believe this applies to

    const e: error{A}!u32 = error.A;
    if (e) |*ptr| {...} else |err| switch (err) {...}
    //      ^ previous range
    //       ^^^ current range

EDIT
I've verified this is now correct and was previously broken in 0.12.0-dev.2158+4f2009de1

@travisstaloch
Copy link
Contributor Author

I think I'm missing some compile error tests. Correct me if I'm wrong, but I think they should go in test/cases/compile_errors. I'm working on adding them now.

@travisstaloch
Copy link
Contributor Author

travisstaloch commented Jan 16, 2024

I've added the compile error tests. Not sure about this stuff:

// error
// backend=stage2
// target=native
//

I copied that from another file in that directory and they pass locally running $ zig build test-cases.

@Vexu Vexu merged commit f335370 into ziglang:master Jan 16, 2024
@travisstaloch travisstaloch deleted the ptr-capture-fixes branch January 16, 2024 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

various incorrect capture by ref ranges

2 participants