commit c61d0ebb36a7e3492da0347568cca1e4af0c2438
parent 2bbeede9c1a3f6b17824e267aad9accabfd47ad6
Author: Eyal Sawady <ecs@d2evs.net>
Date: Mon, 19 Apr 2021 11:26:40 -0400
hare::parse: test struct autofill
And fix the bugs it uncovered
Diffstat:
3 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/hare/parse/+test/expr.ha b/hare/parse/+test/expr.ha
@@ -89,6 +89,7 @@
coords {
x: int = 10,
y: int = 20,
+ ...
};
coords {
x = 10,
@@ -112,6 +113,9 @@
y: int = 20,
},
};
+ coords {
+ ...
+ };
};
");
};
diff --git a/hare/parse/expr.ha b/hare/parse/expr.ha
@@ -612,7 +612,7 @@ fn plain_struct(lexer: *lex::lexer, alias: ast::ident) (ast::expr | error) = {
switch (tok.0) {
ltok::ELLIPSIS => {
synassert(mkloc(lexer), len(alias) != 0,
- "Cannot use auto-fill with anonymous struct");
+ "Cannot use auto-fill with anonymous struct")?;
autofill = true;
try(lexer, ltok::COMMA)?;
want(lexer, ltok::RBRACE)?;
diff --git a/hare/unparse/expr.ha b/hare/unparse/expr.ha
@@ -375,6 +375,10 @@ fn struct_constant(
};
z += fmt::fprint(out, ",")?;
};
+ if (sc.autofill) {
+ newline(out, indent)?;
+ fmt::fprint(out, "...");
+ };
indent -= 1;
newline(out, indent)?;
fmt::fprint(out, "}");