aboutsummaryrefslogtreecommitdiff
path: root/test/cases/syntax.zig
blob: b497b060c4889e8854a3ef9acd28b507062627b0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Test trailing comma syntax
// zig fmt: off

const struct_trailing_comma = struct { x: i32, y: i32, };
const struct_no_comma = struct { x: i32, y: i32 };
const struct_fn_no_comma = struct { fn m() void {} y: i32 };

const enum_no_comma = enum { A, B };

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;

fn fn_calls() void {
    fn add(x: i32, y: i32,) i32 { x + y };
    _ = add(1, 2);
    _ = add(1, 2,);
}

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",);
    }
}