Skip to content

Instantly share code, notes, and snippets.

@nodefish
Created April 15, 2019 14:02
Show Gist options
  • Save nodefish/6ea76ac5646b0d932c303dc620d2dcec to your computer and use it in GitHub Desktop.
Save nodefish/6ea76ac5646b0d932c303dc620d2dcec to your computer and use it in GitHub Desktop.
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