feat: 数组支持 struct 元素类型 [Point; N]
This commit is contained in:
+10
-1
@@ -719,12 +719,21 @@ static void analyze_node(AstNode* node, Scope* scope, ErrorList* errors, Arena*
|
||||
error_add(errors, "<sema>", node->loc.line, node->loc.col,
|
||||
"数组索引必须是 i64 类型, 得到 '%s'", type_name(idx->type.kind));
|
||||
}
|
||||
TypeKind elem_kind = sym->type == TYPE_ARRAY ? TYPE_I64 : sym->type;
|
||||
TypeKind elem_kind = (sym->type == TYPE_ARRAY) ? sym->array_element_type : sym->type;
|
||||
if (val->type.kind != TYPE_ERROR && val->type.kind != elem_kind) {
|
||||
error_add(errors, "<sema>", node->loc.line, node->loc.col,
|
||||
"数组元素类型不匹配: 期望 '%s',得到 '%s'",
|
||||
type_name(elem_kind), type_name(val->type.kind));
|
||||
}
|
||||
// struct 元素类型时还需检查结构体名是否匹配
|
||||
if (val->type.kind != TYPE_ERROR && elem_kind == TYPE_STRUCT
|
||||
&& sym->array_element_struct_name && val->type.struct_name) {
|
||||
if (strcmp(sym->array_element_struct_name, val->type.struct_name) != 0) {
|
||||
error_add(errors, "<sema>", node->loc.line, node->loc.col,
|
||||
"数组元素类型不匹配: 期望 '%s',得到 '%s'",
|
||||
sym->array_element_struct_name, val->type.struct_name);
|
||||
}
|
||||
}
|
||||
node->type.kind = TYPE_VOID;
|
||||
break;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user