-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
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
Dangerous undefined value #21970
Comments
duplicate of #63 (not a bug) |
related #211
|
hi @andrewrk @nektrne thanks for your comments and I know the background to introduce undefined. However, compare to null which is much safer, then whats scenarios should use undefined? If there are cases to be dangerous, I would think undefined should not be used in production. Make an option to turn undefined on/off? |
@nektro also in the code above, this case can be detected, bu no error?even a warning is better. Comptime undefined can be detected |
var buffer: [1024]u8 = undefined;
const slice = foo(&buffer); happy to discuss more in a Community |
Zig Version
0.14.dev
Steps to Reproduce and Observed Behavior
The following code is valid but extremely dangerous, because val is rubbish value. No any warnning messages.
When myfunc is from 3rd party, how do I know the returned value is valid?
Also, I can not even check val value using == undefined because 0.14 will emit an error.
I would suggest undefined value should not be returned when function marked with ?. At least a warning is needed?
fn myfunc() ?u32 {
return undefined;
}
test "aa" {
if (myfunc()) |val| {
std.debug.print("{}\n", .{val});
}
}
Expected Behavior
emit an error
The text was updated successfully, but these errors were encountered: