Add struct #no_copy

This commit is contained in:
gingerBill
2023-04-15 15:36:21 +01:00
parent b7b5043aea
commit 5da76ae34b
9 changed files with 61 additions and 12 deletions

View File

@@ -5043,6 +5043,21 @@ gb_internal isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lh
return tuple_count;
}
gb_internal bool check_no_copy_assignment(Operand const &o, String const &context) {
if (o.type && is_type_no_copy(o.type)) {
Ast *expr = unparen_expr(o.expr);
if (expr && o.mode != Addressing_Constant) {
if (expr->kind == Ast_CallExpr) {
// Okay
} else {
error(o.expr, "Invalid use a #no_copy value in %.*s", LIT(context));
return true;
}
}
}
return false;
}
gb_internal bool check_assignment_arguments(CheckerContext *ctx, Array<Operand> const &lhs, Array<Operand> *operands, Slice<Ast *> const &rhs) {
bool optional_ok = false;
@@ -5114,6 +5129,7 @@ gb_internal bool check_assignment_arguments(CheckerContext *ctx, Array<Operand>
for (Entity *e : tuple->variables) {
o.type = e->type;
array_add(operands, o);
check_no_copy_assignment(o, str_lit("assignment"));
}
tuple_index += tuple->variables.count;
@@ -5952,6 +5968,10 @@ gb_internal CallArgumentData check_call_arguments(CheckerContext *c, Operand *op
}
}
for (Operand const &o : operands) {
check_no_copy_assignment(o, str_lit("call expression"));
}
if (operand->mode == Addressing_ProcGroup) {
check_entity_decl(c, operand->proc_group, nullptr, nullptr);