mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-05 07:08:48 +00:00
Cleaning type hinting for assignments
This commit is contained in:
+6
-6
@@ -3711,7 +3711,7 @@ isize add_dependencies_from_unpacking(CheckerContext *c, Entity **lhs, isize lhs
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void check_assignment_arguments(CheckerContext *ctx, Array<Operand> const &lhs, Array<Operand> *operands, Array<Ast *> const &rhs, bool allow_ok, bool *optional_ok_ = nullptr) {
|
bool check_assignment_arguments(CheckerContext *ctx, Array<Operand> const &lhs, Array<Operand> *operands, Array<Ast *> const &rhs) {
|
||||||
bool optional_ok = false;
|
bool optional_ok = false;
|
||||||
isize tuple_index = 0;
|
isize tuple_index = 0;
|
||||||
for_array(i, rhs) {
|
for_array(i, rhs) {
|
||||||
@@ -3733,7 +3733,7 @@ void check_assignment_arguments(CheckerContext *ctx, Array<Operand> const &lhs,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (o.type == nullptr || o.type->kind != Type_Tuple) {
|
if (o.type == nullptr || o.type->kind != Type_Tuple) {
|
||||||
if (allow_ok && lhs.count == 2 && rhs.count == 1 &&
|
if (lhs.count == 2 && rhs.count == 1 &&
|
||||||
(o.mode == Addressing_MapIndex || o.mode == Addressing_OptionalOk)) {
|
(o.mode == Addressing_MapIndex || o.mode == Addressing_OptionalOk)) {
|
||||||
Type *tuple = make_optional_ok_type(o.type);
|
Type *tuple = make_optional_ok_type(o.type);
|
||||||
add_type_and_value(&c->checker->info, o.expr, o.mode, tuple, o.value);
|
add_type_and_value(&c->checker->info, o.expr, o.mode, tuple, o.value);
|
||||||
@@ -3742,7 +3742,7 @@ void check_assignment_arguments(CheckerContext *ctx, Array<Operand> const &lhs,
|
|||||||
Operand ok = o;
|
Operand ok = o;
|
||||||
val.mode = Addressing_Value;
|
val.mode = Addressing_Value;
|
||||||
ok.mode = Addressing_Value;
|
ok.mode = Addressing_Value;
|
||||||
ok.type = t_bool;
|
ok.type = t_untyped_bool;
|
||||||
array_add(operands, val);
|
array_add(operands, val);
|
||||||
array_add(operands, ok);
|
array_add(operands, ok);
|
||||||
|
|
||||||
@@ -3764,12 +3764,12 @@ void check_assignment_arguments(CheckerContext *ctx, Array<Operand> const &lhs,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optional_ok_) *optional_ok_ = optional_ok;
|
return optional_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array<Operand> *operands, Array<Ast *> const &rhs, bool allow_ok, bool *optional_ok_ = nullptr) {
|
bool check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count, Array<Operand> *operands, Array<Ast *> const &rhs, bool allow_ok) {
|
||||||
bool optional_ok = false;
|
bool optional_ok = false;
|
||||||
isize tuple_index = 0;
|
isize tuple_index = 0;
|
||||||
for_array(i, rhs) {
|
for_array(i, rhs) {
|
||||||
@@ -3826,7 +3826,7 @@ void check_unpack_arguments(CheckerContext *ctx, Entity **lhs, isize lhs_count,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (optional_ok_) *optional_ok_ = optional_ok;
|
return optional_ok;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1122,7 +1122,7 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
check_assignment_arguments(ctx, lhs_operands, &rhs_operands, as->rhs, true);
|
check_assignment_arguments(ctx, lhs_operands, &rhs_operands, as->rhs);
|
||||||
|
|
||||||
isize rhs_count = rhs_operands.count;
|
isize rhs_count = rhs_operands.count;
|
||||||
for_array(i, rhs_operands) {
|
for_array(i, rhs_operands) {
|
||||||
|
|||||||
Reference in New Issue
Block a user