diff options
| author | Ginger Bill <bill@gingerbill.org> | 2017-05-17 21:23:52 +0100 |
|---|---|---|
| committer | Ginger Bill <bill@gingerbill.org> | 2017-05-17 21:23:52 +0100 |
| commit | 41aa4e606b41655b27eb8518ca9a6035c52df273 (patch) | |
| tree | 24f1a78549a99c43c24ef4bebf849a43b6355cb5 /src/check_expr.c | |
| parent | e025a828ca6f8014e11837d6281a14313ec13714 (diff) | |
Optional main for DLL; access struct elements by "index"
Diffstat (limited to 'src/check_expr.c')
| -rw-r--r-- | src/check_expr.c | 15 |
1 files changed, 12 insertions, 3 deletions
diff --git a/src/check_expr.c b/src/check_expr.c index a7e85f819..db31c25ec 100644 --- a/src/check_expr.c +++ b/src/check_expr.c @@ -3054,8 +3054,8 @@ Entity *check_selector(Checker *c, Operand *operand, AstNode *node, Type *type_h return NULL; } - // if (selector->kind != AstNode_Ident && selector->kind != AstNode_BasicLit) { - if (selector->kind != AstNode_Ident) { + if (selector->kind != AstNode_Ident && selector->kind != AstNode_BasicLit) { + // if (selector->kind != AstNode_Ident) { error_node(selector, "Illegal selector kind: `%.*s`", LIT(ast_node_strings[selector->kind])); operand->mode = Addressing_Invalid; operand->expr = node; @@ -5406,6 +5406,15 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t check_assignment(c, o, field->type, str_lit("structure literal")); } } else { + bool all_fields_are_blank = true; + for (isize i = 0; i < t->Record.field_count; i++) { + Entity *field = t->Record.fields_in_src_order[i]; + if (str_ne(field->token.string, str_lit("_"))) { + all_fields_are_blank = false; + break; + } + } + for_array(index, cl->elems) { AstNode *elem = cl->elems.e[index]; if (elem->kind == AstNode_FieldValue) { @@ -5414,7 +5423,7 @@ ExprKind check_expr_base_internal(Checker *c, Operand *o, AstNode *node, Type *t } Entity *field = t->Record.fields_in_src_order[index]; - if (str_eq(field->token.string, str_lit("_"))) { + if (!all_fields_are_blank && str_eq(field->token.string, str_lit("_"))) { // NOTE(bill): Ignore blank identifiers continue; } |