Skip to content

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

Merged
mlugg merged 1 commit into
ziglang:masterfrom
mikastiv:omit-try-note
Jul 31, 2025
Merged

Add note suggesting dropping try on non error-unions#21934
mlugg merged 1 commit into
ziglang:masterfrom
mikastiv:omit-try-note

Conversation

@mikastiv
Copy link
Copy Markdown
Contributor

@mikastiv mikastiv commented Nov 7, 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'

Comment thread src/Sema.zig Outdated
@andrewrk andrewrk self-requested a review November 9, 2024 03:44
@alexrp alexrp modified the milestone: 0.14.0 Jan 30, 2025
@alexrp alexrp requested a review from mlugg March 26, 2025 10:48
Copy link
Copy Markdown
Member

@mlugg mlugg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the delay in review. I'll rebase this and set to auto-merge shortly.

@mlugg mlugg removed the request for review from andrewrk July 30, 2025 10:28
@mlugg mlugg enabled auto-merge (rebase) July 30, 2025 10:37
@mlugg mlugg merged commit 1a15fbe into ziglang:master Jul 31, 2025
15 of 20 checks passed
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

4 participants