3671582c15
The purpose of this is: * Only one way to do things * Changing a function with void return type to return a possible error becomes a 1 character change, subtly encouraging people to use errors. See #632 Here are some imperfect sed commands for performing this update: remove arrow: ``` sed -i 's/\(\bfn\b.*\)-> /\1/g' $(find . -name "*.zig") ``` add void: ``` sed -i 's/\(\bfn\b.*\))\s*{/\1) void {/g' $(find ../ -name "*.zig") ``` Some cleanup may be necessary, but this should do the bulk of the work.
61 lines
1.3 KiB
Zig
61 lines
1.3 KiB
Zig
// Test trailing comma syntax
|
|
|
|
const struct_trailing_comma = struct { x: i32, y: i32, };
|
|
const struct_no_comma = struct { x: i32, y: i32 };
|
|
const struct_no_comma_void_type = struct { x: i32, y };
|
|
const struct_fn_no_comma = struct { fn m() void {} y: i32 };
|
|
|
|
const enum_no_comma = enum { A, B };
|
|
const enum_no_comma_type = enum { A, B: i32 };
|
|
|
|
fn container_init() void {
|
|
const S = struct { x: i32, y: i32 };
|
|
_ = S { .x = 1, .y = 2 };
|
|
_ = S { .x = 1, .y = 2, };
|
|
}
|
|
|
|
fn switch_cases(x: i32) void {
|
|
switch (x) {
|
|
1,2,3 => {},
|
|
4,5, => {},
|
|
6...8, => {},
|
|
else => {},
|
|
}
|
|
}
|
|
|
|
fn switch_prongs(x: i32) void {
|
|
switch (x) {
|
|
0 => {},
|
|
else => {},
|
|
}
|
|
switch (x) {
|
|
0 => {},
|
|
else => {}
|
|
}
|
|
}
|
|
|
|
const fn_no_comma = fn(i32, i32)void;
|
|
const fn_trailing_comma = fn(i32, i32,)void;
|
|
const fn_vararg_trailing_comma = fn(i32, i32, ...,)void;
|
|
|
|
fn fn_calls() void {
|
|
fn add(x: i32, y: i32,) i32 { x + y };
|
|
_ = add(1, 2);
|
|
_ = add(1, 2,);
|
|
|
|
fn swallow(x: ...,) void {};
|
|
_ = swallow(1,2,3,);
|
|
_ = swallow();
|
|
}
|
|
|
|
fn asm_lists() void {
|
|
if (false) { // Build AST but don't analyze
|
|
asm ("not real assembly"
|
|
:[a] "x" (x),);
|
|
asm ("not real assembly"
|
|
:[a] "x" (->i32),:[a] "x" (1),);
|
|
asm ("still not real assembly"
|
|
:::"a","b",);
|
|
}
|
|
}
|