/struct_fn_shadowing.zig Secret
Created
April 15, 2019 14:02
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
fn something() i32 { | |
return 500; | |
} | |
const SomeStruct = struct { | |
data: []const u8, | |
pub fn something() i32 { | |
return 300; | |
} | |
pub fn somethingElse(self: *const @This()) i32 { | |
return something(); | |
} | |
pub fn somethingStatic() i32 { | |
return something(); | |
} | |
}; | |
test "something" { | |
const some_struct = SomeStruct{ .data = undefined }; | |
std.debug.warn("\n"); | |
std.debug.warn("{}\n", some_struct.somethingElse()); // prints 300 -> `instance.something()` shadows top-level `fn something` | |
std.debug.warn("{}\n", SomeStruct.somethingStatic()); // prints 300 -> `struct.something()` shadows top-level `fn something` | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment