Name collision between function argument and other function

Say I want to provide a function foo which gets an argument bar, and also a totally unrelated function bar. How do I do this?

pub fn foo(bar: i32) void {
    _ = bar;
}

pub fn bar() void {
}

Gives:

shadow.zig:1:12: error: function parameter shadows declaration of 'bar'
pub fn foo(bar: i32) void {
           ^~~
shadow.zig:5:5: note: declared here
pub fn bar() void {
~~~~^~

My attempt to solve it with an alias (expectedly) fails as well:

 pub fn foo(bar: i32) void {
-    _ = bar;
+    const my_bar = bar;
+    _ = my_bar;
 }

Any way around this? (Without having to rename the argument, which would have effects on created documentation, of course.)

There are only two options:
Either you rename one of them, or you put them in separate namespaces or separate files.

2 Likes

I wonder if the documentation tool could rename a bar_ argument to bar automatically (in the future).