mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-04 22:58:46 +00:00
Restrict global variables to not allow tuples
This commit is contained in:
+2
-2
@@ -825,7 +825,7 @@ void check_struct_field_decl(Checker *c, AstNode *decl, Array<Entity *> *fields,
|
|||||||
is_using = false;
|
is_using = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool arity_ok = check_arity_match(c, vd);
|
bool arity_ok = check_arity_match(c, vd, false);
|
||||||
|
|
||||||
if (vd->values.count > 0 && !allow_default_values) {
|
if (vd->values.count > 0 && !allow_default_values) {
|
||||||
error(vd->values[0], "Default values are not allowed within a %.*s", LIT(context));
|
error(vd->values[0], "Default values are not allowed within a %.*s", LIT(context));
|
||||||
@@ -5996,7 +5996,7 @@ void check_unpack_arguments(Checker *c, Entity **lhs, isize lhs_count, Array<Ope
|
|||||||
Operand o = {};
|
Operand o = {};
|
||||||
|
|
||||||
if (lhs != nullptr && tuple_index < lhs_count) {
|
if (lhs != nullptr && tuple_index < lhs_count) {
|
||||||
// NOTE(bill): override DeclInfo for dependency control
|
// NOTE(bill): override DeclInfo for dependency
|
||||||
DeclInfo *decl = decl_info_of_entity(&c->info, lhs[tuple_index]);
|
DeclInfo *decl = decl_info_of_entity(&c->info, lhs[tuple_index]);
|
||||||
if (decl) c->context.decl = decl;
|
if (decl) c->context.decl = decl;
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -1757,7 +1757,7 @@ void check_stmt_internal(Checker *c, AstNode *node, u32 flags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
check_arity_match(c, vd);
|
check_arity_match(c, vd, false);
|
||||||
check_init_variables(c, entities, entity_count, vd->values, str_lit("variable declaration"));
|
check_init_variables(c, entities, entity_count, vd->values, str_lit("variable declaration"));
|
||||||
|
|
||||||
for (isize i = 0; i < entity_count; i++) {
|
for (isize i = 0; i < entity_count; i++) {
|
||||||
|
|||||||
+16
-14
@@ -1604,7 +1604,7 @@ void init_preload(Checker *c) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool check_arity_match(Checker *c, AstNodeValueDecl *vd);
|
bool check_arity_match(Checker *c, AstNodeValueDecl *vd, bool is_global);
|
||||||
void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_scope);
|
void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_scope);
|
||||||
void check_collect_entities_from_when_stmt(Checker *c, AstNodeWhenStmt *ws, bool is_file_scope);
|
void check_collect_entities_from_when_stmt(Checker *c, AstNodeWhenStmt *ws, bool is_file_scope);
|
||||||
|
|
||||||
@@ -1726,7 +1726,7 @@ void check_procedure_overloading(Checker *c, Entity *e) {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
bool check_arity_match(Checker *c, AstNodeValueDecl *vd) {
|
bool check_arity_match(Checker *c, AstNodeValueDecl *vd, bool is_global) {
|
||||||
isize lhs = vd->names.count;
|
isize lhs = vd->names.count;
|
||||||
isize rhs = vd->values.count;
|
isize rhs = vd->values.count;
|
||||||
|
|
||||||
@@ -1745,12 +1745,18 @@ bool check_arity_match(Checker *c, AstNodeValueDecl *vd) {
|
|||||||
error(vd->names[0], "Extra initial expression");
|
error(vd->names[0], "Extra initial expression");
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
} else if (lhs > rhs && rhs != 1) {
|
} else if (lhs > rhs) {
|
||||||
AstNode *n = vd->names[rhs];
|
if (!is_global && rhs != 1) {
|
||||||
gbString str = expr_to_string(n);
|
AstNode *n = vd->names[rhs];
|
||||||
error(n, "Missing expression for `%s`", str);
|
gbString str = expr_to_string(n);
|
||||||
gb_string_free(str);
|
error(n, "Missing expression for `%s`", str);
|
||||||
return false;
|
gb_string_free(str);
|
||||||
|
return false;
|
||||||
|
} else if (is_global) {
|
||||||
|
AstNode *n = vd->values[rhs-1];
|
||||||
|
error(n, "Expected %td expressions on the right hand side, got %td", lhs, rhs);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -1884,11 +1890,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_sco
|
|||||||
di->entity_count = entity_count;
|
di->entity_count = entity_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vd->values.count > 0 && entity_count != vd->values.count) {
|
check_arity_match(c, vd, true);
|
||||||
error(decl, "Variable declarations in the global scope can only declare 1 variable at a time");
|
|
||||||
}
|
|
||||||
|
|
||||||
check_arity_match(c, vd);
|
|
||||||
} else {
|
} else {
|
||||||
for_array(i, vd->names) {
|
for_array(i, vd->names) {
|
||||||
AstNode *name = vd->names[i];
|
AstNode *name = vd->names[i];
|
||||||
@@ -1952,7 +1954,7 @@ void check_collect_entities(Checker *c, Array<AstNode *> nodes, bool is_file_sco
|
|||||||
add_entity_and_decl_info(c, name, e, d);
|
add_entity_and_decl_info(c, name, e, d);
|
||||||
}
|
}
|
||||||
|
|
||||||
check_arity_match(c, vd);
|
check_arity_match(c, vd, true);
|
||||||
}
|
}
|
||||||
case_end;
|
case_end;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user