We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
try
0.14.0-dev.2126+e27b4647d
The compiler doesn't report an error message here and these 3 tests all pass.
const std = @import("std"); test { const S = struct { a: u8 }; const s: S = try .{ .a = 0 }; // try makes no sense here try std.testing.expectEqual(0, s.a); }
I originally noticed this while refactoring some code and forgot to remove try from a switch statement, similar to these
test { const S = struct { a: u8 }; const s: S = switch (0) { 0 => try .{ .a = 0 }, // try makes no sense here else => unreachable, }; try std.testing.expectEqual(0, s.a); } test { const S = struct { a: u8 }; const s: S = if (true) try .{ .a = 0 } // try makes no sense here else unreachable; try std.testing.expectEqual(0, s.a); }
I would expect an error message like this:
test { const S = struct { a: u8 }; const s = try S{ .a = 0 }; try std.testing.expectEqual(0, s.a); }
$ zig test /tmp/tmp.zig /tmp/tmp.zig:5:23: error: expected error union type, found 'tmp.test_0.S' const s: S = try S{ .a = 0 }; ~^~~~~~~~~~ /tmp/tmp.zig:4:15: note: struct declared here const S = struct { a: u8 }; ^~~~~~~~~~~~~~~~
The text was updated successfully, but these errors were encountered:
No branches or pull requests
Zig Version
0.14.0-dev.2126+e27b4647d
Steps to Reproduce and Observed Behavior
The compiler doesn't report an error message here and these 3 tests all pass.
I originally noticed this while refactoring some code and forgot to remove
try
from a switch statement, similar to theseExpected Behavior
I would expect an error message like this:
The text was updated successfully, but these errors were encountered: