mirror of
https://github.com/Ed94/Odin.git
synced 2026-07-09 21:11:36 -07:00
Prevent returning struct containing compound literal slice
This commit is contained in:
@@ -2671,6 +2671,20 @@ gb_internal void check_return_stmt(CheckerContext *ctx, Ast *node) {
|
||||
ERROR_BLOCK();
|
||||
unsafe_return_error(o, "a compound literal of a slice");
|
||||
error_line("\tNote: A constant slice value will use the memory of the current stack frame\n");
|
||||
} else if (expr->kind == Ast_CompoundLit && is_type_struct(o.type)) {
|
||||
ast_node(cl, CompoundLit, expr);
|
||||
for (Ast *elem : cl->elems) {
|
||||
if (elem->kind == Ast_FieldValue) {
|
||||
ast_node(fv, FieldValue, elem);
|
||||
if (fv->value->kind == Ast_CompoundLit && is_type_slice(entity_of_node(fv->field)->type)) {
|
||||
ast_node(sl, CompoundLit, fv->value);
|
||||
if (sl->elems.count == 0) {
|
||||
continue;
|
||||
}
|
||||
unsafe_return_error(o, "a compound literal containing a slice");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user