mirror of
https://github.com/ziglang/zig.git
synced 2026-01-25 00:35:20 +00:00
31 lines
643 B
Zig
31 lines
643 B
Zig
const StructWithNoFields = struct {
|
|
fn add(a: i32, b: i32) -> i32 { a + b }
|
|
};
|
|
const empty_global_instance = StructWithNoFields {};
|
|
|
|
fn callStructStaticMethod() {
|
|
@setFnTest(this);
|
|
const result = StructWithNoFields.add(3, 4);
|
|
assert(result == 7);
|
|
}
|
|
|
|
fn returnEmptyStructInstance() -> StructWithNoFields {
|
|
@setFnTest(this);
|
|
return empty_global_instance;
|
|
}
|
|
|
|
const should_be_11 = StructWithNoFields.add(5, 6);
|
|
|
|
fn invokeStaticMethodInGlobalScope() {
|
|
@setFnTest(this);
|
|
assert(should_be_11 == 11);
|
|
}
|
|
|
|
|
|
|
|
// TODO const assert = @import("std").debug.assert;
|
|
fn assert(ok: bool) {
|
|
if (!ok)
|
|
@unreachable();
|
|
}
|