stage1 修复类型重复解析 修复嵌套结构体字面量无限循环

This commit is contained in:
zzy
2026-07-12 14:20:41 +08:00
parent 9b9b25ce0f
commit 1ceda90207
2 changed files with 48 additions and 7 deletions

View File

@@ -467,7 +467,12 @@ static void parse_one_field_init(spl_comp_t *ctx, spl_field_vec_t *fields, int b
spl_emit(ctx, SPL_DROP, SPL_VOID, 0);
} else if (f->type && (f->type->kind == TYPE_STRUCT || f->type->kind == TYPE_ENUM) &&
spl_type_size(f->type) > sizeof(spl_val_t)) {
spl_expr_result_t fv = spl_parse_expr(ctx, PREC_MIN);
spl_expr_result_t fv;
if (peek(ctx)->type == TOK_L_BRACE) {
fv = spl_parse_struct_literal(ctx, f->type);
} else {
fv = spl_parse_expr(ctx, PREC_MIN);
}
(void)fv;
usize nslots = (spl_type_size(f->type) + sizeof(spl_val_t) - 1) / sizeof(spl_val_t);
spl_emit_copy_slots(ctx, base_offset + (int)extra_offset + f->offset, nslots);
@@ -583,7 +588,12 @@ spl_expr_result_t spl_parse_struct_literal(spl_comp_t *ctx, spl_type_info_t *typ
(v->data_type->kind == TYPE_STRUCT ||
v->data_type->kind == TYPE_ENUM) &&
spl_type_size(v->data_type) > sizeof(spl_val_t)) {
spl_expr_result_t dv = spl_parse_expr(ctx, PREC_MIN);
spl_expr_result_t dv;
if (peek(ctx)->type == TOK_L_BRACE) {
dv = spl_parse_struct_literal(ctx, v->data_type);
} else {
dv = spl_parse_expr(ctx, PREC_MIN);
}
(void)dv;
usize nslots = (spl_type_size(v->data_type) + sizeof(spl_val_t) - 1) /
sizeof(spl_val_t);