Ast: properly handle sentinel-terminated slices in tuple

Co-authored-by: Veikka Tuominen <git@vexu.eu>
This commit is contained in:
r00ster91 2023-03-03 09:42:34 +01:00 committed by Veikka Tuominen
parent 75ff34db9e
commit e0d3904638
2 changed files with 25 additions and 3 deletions

View File

@ -1407,7 +1407,8 @@ pub fn containerField(tree: Ast, node: Node.Index) full.ContainerField {
.type_expr = data.lhs,
.value_expr = extra.value_expr,
.align_expr = extra.align_expr,
.tuple_like = tree.tokens.items(.tag)[main_token + 1] != .colon,
.tuple_like = tree.tokens.items(.tag)[main_token] != .identifier or
tree.tokens.items(.tag)[main_token + 1] != .colon,
});
}
@ -1420,7 +1421,8 @@ pub fn containerFieldInit(tree: Ast, node: Node.Index) full.ContainerField {
.type_expr = data.lhs,
.value_expr = data.rhs,
.align_expr = 0,
.tuple_like = tree.tokens.items(.tag)[main_token + 1] != .colon,
.tuple_like = tree.tokens.items(.tag)[main_token] != .identifier or
tree.tokens.items(.tag)[main_token + 1] != .colon,
});
}
@ -1433,7 +1435,8 @@ pub fn containerFieldAlign(tree: Ast, node: Node.Index) full.ContainerField {
.type_expr = data.lhs,
.value_expr = 0,
.align_expr = data.rhs,
.tuple_like = tree.tokens.items(.tag)[main_token + 1] != .colon,
.tuple_like = tree.tokens.items(.tag)[main_token] != .identifier or
tree.tokens.items(.tag)[main_token + 1] != .colon,
});
}

View File

@ -397,3 +397,22 @@ test "nested runtime conditionals in tuple initializer" {
};
try expectEqualStrings("up", x[0]);
}
test "sentinel slice in tuple with other fields" {
const S = struct {
a: u32,
b: u32,
};
const Submission = union(enum) {
open: struct { *S, [:0]const u8, u32 },
};
_ = Submission;
}
test "sentinel slice in tuple" {
const S = struct { [:0]const u8 };
_ = S;
}