mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 23:28:48 +00:00
Check to see if people are return a slice of a local fixed array from a procedure
This commit is contained in:
+9
-1
@@ -2517,7 +2517,7 @@ gb_internal void check_return_stmt(CheckerContext *ctx, Ast *node) {
|
|||||||
Entity *e = entity_of_node(x);
|
Entity *e = entity_of_node(x);
|
||||||
if (is_entity_local_variable(e)) {
|
if (is_entity_local_variable(e)) {
|
||||||
unsafe_return_error(o, "the address of a local variable");
|
unsafe_return_error(o, "the address of a local variable");
|
||||||
} else if(x->kind == Ast_CompoundLit) {
|
} else if (x->kind == Ast_CompoundLit) {
|
||||||
unsafe_return_error(o, "the address of a compound literal");
|
unsafe_return_error(o, "the address of a compound literal");
|
||||||
} else if (x->kind == Ast_IndexExpr) {
|
} else if (x->kind == Ast_IndexExpr) {
|
||||||
Entity *f = entity_of_node(x->IndexExpr.expr);
|
Entity *f = entity_of_node(x->IndexExpr.expr);
|
||||||
@@ -2532,6 +2532,14 @@ gb_internal void check_return_stmt(CheckerContext *ctx, Ast *node) {
|
|||||||
unsafe_return_error(o, "the address of an indexed variable", f->type);
|
unsafe_return_error(o, "the address of an indexed variable", f->type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (expr->kind == Ast_SliceExpr) {
|
||||||
|
Ast *x = unparen_expr(expr->SliceExpr.expr);
|
||||||
|
Entity *e = entity_of_node(x);
|
||||||
|
if (is_entity_local_variable(e) && is_type_array(e->type)) {
|
||||||
|
unsafe_return_error(o, "a slice of a local variable");
|
||||||
|
} else if (x->kind == Ast_CompoundLit) {
|
||||||
|
unsafe_return_error(o, "a slice of a compound literal");
|
||||||
|
}
|
||||||
} else if (o.mode == Addressing_Constant && is_type_slice(o.type)) {
|
} else if (o.mode == Addressing_Constant && is_type_slice(o.type)) {
|
||||||
ERROR_BLOCK();
|
ERROR_BLOCK();
|
||||||
unsafe_return_error(o, "a compound literal of a slice");
|
unsafe_return_error(o, "a compound literal of a slice");
|
||||||
|
|||||||
Reference in New Issue
Block a user