Skip to content

Instantly share code, notes, and snippets.

@nrdmn

nrdmn/tuples.md Secret

Created March 8, 2020 18:06
Show Gist options
  • Save nrdmn/5d7a3b252d202a20c03f83809145b642 to your computer and use it in GitHub Desktop.
Save nrdmn/5d7a3b252d202a20c03f83809145b642 to your computer and use it in GitHub Desktop.
tuple assignment
test "" {
    const T = struct {
        @"0": u8,
        @"1": bool,
    };
    const x: T = .{ 5, true };
}

// Semantic Analysis [827/1103] ./test.zig:6:21: error: array access of non-array type 'T'
//     const x: T = .{ 5, true };
test "" {
    const T = @TypeOf(.{ 5, true });
    const x: T = .{ 5, true };
}

// Semantic Analysis [826/1102] ./test.zig:3:19: error: type 'struct:2:24' does not support array initialization
//     const x: T = .{ 5, true };
test "" {
    const T = @TypeOf(.{ 5, true });
    const x: T = .{ .@"0" = 5, .@"1" = true };
}

// works
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment