Hi there, I'm writing the zig code with Version 0.15.1, and when I was writing a function:
fntester(a:i32,b:?i32)i32{b=borelse10;returna+b;}pubfnmain()void{std.debug.print("Result: {d}",.{tester(1)});}
I'm expecting for the result 11, but the compiler returned an error message:
main.zig:9:1: note: function declared here
fn tester(a: i32, b: ?i32) i32 {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
callMain [inlined]: xxx/zig-x86_64-linux/lib/std/start.zig:627:37
callMainWithArgs [inlined]: xxx/zig-x86_64-linux/lib/std/start.zig:587:20
posixCallMainAndExit: xxx/zig-x86_64-linux/lib/std/start.zig:542:36
2 reference(s) hidden; use '-freference-trace=5' to see all references
I'm wondering if there's a plan to add optional function arguments? If ?type represents type or null, then it's silly for compiler to give such a message, since it's optional.
Or maybe we can add default value to the arguments? Just like:
pub fn tester(a: i32 = 1, b: i32 = 10) i32 {
// ...
}
Thanks!
Hi there, I'm writing the zig code with Version 0.15.1, and when I was writing a function:
```zig
fn tester(a: i32, b: ?i32) i32 {
b = b orelse 10;
return a + b;
}
pub fn main() void {
std.debug.print("Result: {d}", .{tester(1)});
}
```
I'm expecting for the result 11, but the compiler returned an error message:
main.zig:9:1: note: function declared here
fn tester(a: i32, b: ?i32) i32 {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
referenced by:
callMain [inlined]: xxx/zig-x86_64-linux/lib/std/start.zig:627:37
callMainWithArgs [inlined]: xxx/zig-x86_64-linux/lib/std/start.zig:587:20
posixCallMainAndExit: xxx/zig-x86_64-linux/lib/std/start.zig:542:36
2 reference(s) hidden; use '-freference-trace=5' to see all references
I'm wondering if there's a plan to add optional function arguments? If `?type` represents `type or null`, then it's silly for compiler to give such a message, since it's optional.
Or maybe we can add default value to the arguments? Just like:
```
pub fn tester(a: i32 = 1, b: i32 = 10) i32 {
// ...
}
```
Thanks!