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
In the following code, notNull is always null:
notNull
null
const std = @import("std"); fn maybe2(num: u32) anyerror!?u32 { return num; } fn maybe(should: enum{Yes, No}, num: u32) anyerror!?u32 { return switch (should) { .Yes => maybe2(num), else => null, }; } test "incorrect return" { const notNull = maybe(.Yes, 12) catch unreachable; // error: attempt to unwrap null std.testing.expect(notNull.? == 12); }
The following cases work as expected:
const std = @import("std"); fn maybe2(num: u32) ?u32 { return num; } fn maybe(should: enum{Yes, No}, num: u32) ?u32 { return switch (should) { .Yes => maybe2(num), else => null, }; } test "incorrect return" { const notNull = maybe(.Yes, 12); std.testing.expect(notNull.? == 12); }
const std = @import("std"); fn maybe(should: enum{Yes, No}, num: u32) anyerror!?u32 { return switch (should) { .Yes => num, else => null, }; } test "incorrect return" { const notNull = maybe(.Yes, 12) catch unreachable; std.testing.expect(notNull.? == 12); }
const std = @import("std"); fn maybe2(num: u32) ?u32 { return num; } fn maybe(should: enum{Yes, No}, num: u32) anyerror!?u32 { return switch (should) { .Yes => maybe2(num), .No => null, }; } test "incorrect return" { const notNull = maybe(.Yes, 12) catch unreachable; std.testing.expect(notNull.? == 12); }
In the first example, replacing else with .No, you get error: expected type 'u32', found '(null)' when compiling. Zig version is 0.4.0+7d9ee5d6d
else
.No
error: expected type 'u32', found '(null)'
0.4.0+7d9ee5d6d
The text was updated successfully, but these errors were encountered:
Fix result loc unwrapping with optional in error union
6d6e4c9
Fixes ziglang#2899
5fb7af2
Successfully merging a pull request may close this issue.
In the following code,
notNull
is alwaysnull
:The following cases work as expected:
In the first example, replacing
else
with.No
, you geterror: expected type 'u32', found '(null)'
when compiling. Zig version is0.4.0+7d9ee5d6d
The text was updated successfully, but these errors were encountered: