Zig 0.17.0-dev (Split by item)

This is an example of documentation generated by ZigDoc, an alternative to Zig's built-in Auto Doc feature. See also examples in other modes/formats. The project being documented here (as the example) is the Zig library itself.

checkLabelRedefinition

AstGen.checkLabelRedefinition
fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: Ast.TokenIndex) !void

File

lib/std/zig/AstGen.zig:2445

Code

fn checkLabelRedefinition(astgen: *AstGen, parent_scope: *Scope, label: Ast.TokenIndex) !void {
    // Look for the label in the scope.
    find_scope: switch (parent_scope.unwrap()) {
        .gen_zir => |gen_zir| {
            if (gen_zir.label) |prev_label| {
                if (try astgen.tokenIdentEql(label, prev_label.token)) {
                    const label_name = try astgen.identifierTokenString(label);
                    return astgen.failTokNotes(label, "redefinition of label '{s}'", .{
                        label_name,
                    }, &[_]u32{
                        try astgen.errNoteTok(
                            prev_label.token,
                            "previous definition here",
                            .{},
                        ),
                    });
                }
            }
            continue :find_scope gen_zir.parent.unwrap();
        },
        .local_val => |local_val| continue :find_scope local_val.parent.unwrap(),
        .local_ptr => |local_ptr| continue :find_scope local_ptr.parent.unwrap(),
        .defer_normal, .defer_error => |defer_scope| continue :find_scope defer_scope.parent.unwrap(),
        .namespace => break :find_scope,
        .top => unreachable,
    }
}