mirror of
https://github.com/Ed94/Odin.git
synced 2026-06-25 07:04:58 -07:00
map literals
This commit is contained in:
+28
-3
@@ -2885,14 +2885,14 @@ bool check_builtin_procedure(Checker *c, Operand *operand, AstNode *call, i32 id
|
||||
Type *type = operand->type;
|
||||
if (!is_type_pointer(type)) {
|
||||
gbString str = type_to_string(type);
|
||||
error_node(operand->expr, "Expected a pointer to a dynamic array, got `%s`", str);
|
||||
error_node(operand->expr, "Expected a pointer, got `%s`", str);
|
||||
gb_string_free(str);
|
||||
return false;
|
||||
}
|
||||
type = type_deref(type);
|
||||
if (!is_type_dynamic_array(type)) {
|
||||
if (!is_type_dynamic_array(type) && !is_type_map(type)) {
|
||||
gbString str = type_to_string(type);
|
||||
error_node(operand->expr, "Expected a pointer to a dynamic array, got `%s`", str);
|
||||
error_node(operand->expr, "Expected a pointer to a map or dynamic array, got `%s`", str);
|
||||
gb_string_free(str);
|
||||
return false;
|
||||
}
|
||||
@@ -4750,6 +4750,31 @@ ExprKind check__expr_base(Checker *c, Operand *o, AstNode *node, Type *type_hint
|
||||
}
|
||||
} break;
|
||||
|
||||
case Type_Map: {
|
||||
if (cl->elems.count == 0) {
|
||||
break;
|
||||
}
|
||||
is_constant = false;
|
||||
{ // Checker values
|
||||
for_array(i, cl->elems) {
|
||||
AstNode *elem = cl->elems.e[i];
|
||||
if (elem->kind != AstNode_FieldValue) {
|
||||
error_node(elem, "Only `field = value` elements are allowed in a map literal");
|
||||
continue;
|
||||
}
|
||||
ast_node(fv, FieldValue, elem);
|
||||
check_expr_with_type_hint(c, o, fv->field, t->Map.key);
|
||||
check_assignment(c, o, t->Map.key, str_lit("map literal"));
|
||||
if (o->mode == Addressing_Invalid) {
|
||||
continue;
|
||||
}
|
||||
|
||||
check_expr_with_type_hint(c, o, fv->value, t->Map.value);
|
||||
check_assignment(c, o, t->Map.value, str_lit("map literal"));
|
||||
}
|
||||
}
|
||||
} break;
|
||||
|
||||
default: {
|
||||
gbString str = type_to_string(type);
|
||||
error_node(node, "Invalid compound literal type `%s`", str);
|
||||
|
||||
Reference in New Issue
Block a user