parser: fix not setting container init kind
This commit is contained in:
parent
dc162c7f83
commit
8818c59cbc
|
@ -1318,6 +1318,16 @@ static TypeStructField *find_struct_type_field(TypeTableEntry *type_entry, Buf *
|
||||||
return nullptr;
|
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,
|
static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry *import, BlockContext *context,
|
||||||
AstNode *node)
|
AstNode *node)
|
||||||
{
|
{
|
||||||
|
@ -1331,9 +1341,8 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
|
||||||
|
|
||||||
if (container_type->id == TypeTableEntryIdInvalid) {
|
if (container_type->id == TypeTableEntryIdInvalid) {
|
||||||
return container_type;
|
return container_type;
|
||||||
} else if (container_type->id == TypeTableEntryIdStruct) {
|
} else if (container_type->id == TypeTableEntryIdStruct &&
|
||||||
switch (kind) {
|
kind == ContainerInitKindStruct)
|
||||||
case ContainerInitKindStruct:
|
|
||||||
{
|
{
|
||||||
StructValExprCodeGen *codegen = &container_init_expr->resolved_struct_val_expr;
|
StructValExprCodeGen *codegen = &container_init_expr->resolved_struct_val_expr;
|
||||||
codegen->type_entry = container_type;
|
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)));
|
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;
|
return container_type;
|
||||||
} else if (container_type->id == TypeTableEntryIdArray) {
|
} else if (container_type->id == TypeTableEntryIdArray) {
|
||||||
zig_panic("TODO array container init");
|
zig_panic("TODO array container init");
|
||||||
|
@ -1409,7 +1410,8 @@ static TypeTableEntry *analyze_container_init_expr(CodeGen *g, ImportTableEntry
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
add_node_error(g, node,
|
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;
|
return g->builtin_types.entry_invalid;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1423,6 +1423,7 @@ static AstNode *ast_parse_curly_suffix_expr(ParseContext *pc, int *token_index,
|
||||||
|
|
||||||
Token *token = &pc->tokens->at(*token_index);
|
Token *token = &pc->tokens->at(*token_index);
|
||||||
if (token->id == TokenIdDot) {
|
if (token->id == TokenIdDot) {
|
||||||
|
node->data.container_init_expr.kind = ContainerInitKindStruct;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (token->id == TokenIdDot) {
|
if (token->id == TokenIdDot) {
|
||||||
ast_eat_token(pc, token_index, 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 {
|
} else {
|
||||||
|
node->data.container_init_expr.kind = ContainerInitKindArray;
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (token->id == TokenIdRBrace) {
|
if (token->id == TokenIdRBrace) {
|
||||||
*token_index += 1;
|
*token_index += 1;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user