From 7e8604daeb9239e1669c5414dd6caa37af30c4ff Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sat, 11 Oct 2025 15:31:38 -0400 Subject: Make `{a,b,c}` shorthand for `{a:Empty(), b:Empty(), c:Empty()}` and display it that way. Same for type annotations. --- src/compile/tables.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/compile/tables.c') diff --git a/src/compile/tables.c b/src/compile/tables.c index 2b6d3538..958e5af5 100644 --- a/src/compile/tables.c +++ b/src/compile/tables.c @@ -10,8 +10,10 @@ static ast_t *add_to_table_comprehension(ast_t *entry, ast_t *subject) { DeclareMatch(e, entry, TableEntry); - return WrapAST(entry, MethodCall, .name = "set", .self = subject, - .args = new (arg_ast_t, .value = e->key, .next = new (arg_ast_t, .value = e->value))); + return WrapAST( + entry, MethodCall, .name = "set", .self = subject, + .args = new (arg_ast_t, .value = e->key, + .next = new (arg_ast_t, .value = e->value ? e->value : WrapAST(entry, Var, .name = "EMPTY")))); } Text_t compile_typed_table(env_t *env, ast_t *ast, type_t *table_type) { @@ -47,8 +49,10 @@ Text_t compile_typed_table(env_t *env, ast_t *ast, type_t *table_type) { for (ast_list_t *entry = table->entries; entry; entry = entry->next) { DeclareMatch(e, entry->ast, TableEntry); - code = Texts(code, ",\n\t{", compile_to_type(key_scope, e->key, key_t), ", ", - compile_to_type(value_scope, e->value, value_t), "}"); + code = Texts( + code, ",\n\t{", compile_to_type(key_scope, e->key, key_t), ", ", + compile_to_type(value_scope, e->value ? e->value : WrapAST(entry->ast, Var, .name = "EMPTY"), value_t), + "}"); } return Texts(code, ")"); } -- cgit v1.2.3