parser: fix not setting container init kind

This commit is contained in:
Andrew Kelley 2016-01-15 19:02:04 -07:00
parent dc162c7f83
commit 8818c59cbc
2 changed files with 49 additions and 45 deletions

View File

@ -1318,6 +1318,16 @@ static TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *
return nullptr;
}
static const char *err_container_init_syntax_name(ContainerInitKind kind) {
switch (kind) {
case ContainerInitKindStruct:
return "struct";
case ContainerInitKindArray:
return "array";
}
zig_unreachable();
}
static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context,
AstNode *node)
{
@ -1331,9 +1341,8 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
if (container_type->id == TypeTableEntryIdInvalid) {
return container_type;
} else if (container_type->id == TypeTableEntryIdStruct) {
switch (kind) {
case ContainerInitKindStruct:
} else if (container_type->id == TypeTableEntryIdStruct &&
kind == ContainerInitKindStruct)
{
StructValExprCodeGen *codegen = &container_init_expr->resolved_struct_val_expr;
codegen->type_entry = container_type;
@ -1378,14 +1387,6 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
buf_sprintf("missing field: '%s'", buf_ptr(container_type->data.structure.fields[i].name)));
}
}
break;
}
case ContainerInitKindArray:
add_node_error(g, node,
buf_sprintf("struct '%s' does not support array initialization syntax",
buf_ptr(&container_type->name)));
break;
}
return container_type;
} else if (container_type->id == TypeTableEntryIdArray) {
zig_panic("TODO array container init");
@ -1409,7 +1410,8 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
}
} else {
add_node_error(g, node,
buf_sprintf("type '%s' does not support initialization syntax", buf_ptr(&container_type->name)));
buf_sprintf("type '%s' does not support %s syntax",
buf_ptr(&container_type->name), err_container_init_syntax_name(kind)));
return g->builtin_types.entry_invalid;
}
}

View File

@ -1423,6 +1423,7 @@ static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc, int *token_index,
Token *token = &pc->tokens->at(*token_index);
if (token->id == TokenIdDot) {
node->data.container_init_expr.kind = ContainerInitKindStruct;
for (;;) {
if (token->id == TokenIdDot) {
ast_eat_token(pc, token_index, TokenIdDot);
@ -1456,6 +1457,7 @@ static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc, int *token_index,
}
} else {
node->data.container_init_expr.kind = ContainerInitKindArray;
for (;;) {
if (token->id == TokenIdRBrace) {
*token_index += 1;