Skip to content

Add note suggesting dropping try on non error-unions#21903

Closed
mikastiv wants to merge 0 commit into
ziglang:masterfrom
mikastiv:master
Closed

Add note suggesting dropping try on non error-unions#21903
mikastiv wants to merge 0 commit into
ziglang:masterfrom
mikastiv:master

Conversation

@mikastiv
Copy link
Copy Markdown
Contributor

@mikastiv mikastiv commented Nov 4, 2024

Resolves #21845

Output on test/cases/compile_errors/comptime_try_non_error.zig:

test/cases/compile_errors/comptime_try_non_error.zig:6:12: error: expected error union type, found 'u8'
    try bar();
        ~~~^~
test/cases/compile_errors/comptime_try_non_error.zig:6:12: note: consider omitting 'try'
test/cases/compile_errors/comptime_try_non_error.zig:2:8: note: called from here
    foo();
    ~~~^~

Output on example from issue:

> stage4/bin/zig build-exe a.zig
a.zig:6:44: error: expected error union type, found 'array_list.ArrayListAligned(u8,null)'
    const list = try std.ArrayList(u8).init(std.heap.page_allocator);
                     ~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
a.zig:6:44: note: consider omitting 'try'

@mikastiv
Copy link
Copy Markdown
Contributor Author

mikastiv commented Nov 7, 2024

I wanted to sync master on my fork 😕, new PR #21934

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.

Calling try with a non-error-union argument, could suggest dropping the try call

1 participant