mirror of
https://github.com/Ed94/Odin.git
synced 2026-08-06 15:48:51 +00:00
Allow x in ptr_to_map_or_bit_set
This commit is contained in:
+11
-9
@@ -2597,15 +2597,16 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint
|
|||||||
|
|
||||||
case Token_in:
|
case Token_in:
|
||||||
case Token_not_in:
|
case Token_not_in:
|
||||||
|
{
|
||||||
// IMPORTANT NOTE(bill): This uses right-left evaluation in type checking only no in
|
// IMPORTANT NOTE(bill): This uses right-left evaluation in type checking only no in
|
||||||
|
|
||||||
check_expr(c, y, be->right);
|
check_expr(c, y, be->right);
|
||||||
|
Type *rhs_type = type_deref(y->type);
|
||||||
|
|
||||||
if (is_type_bit_set(y->type)) {
|
if (is_type_bit_set(rhs_type)) {
|
||||||
Type *elem = base_type(y->type)->BitSet.elem;
|
Type *elem = base_type(rhs_type)->BitSet.elem;
|
||||||
check_expr_with_type_hint(c, x, be->left, elem);
|
check_expr_with_type_hint(c, x, be->left, elem);
|
||||||
} else if (is_type_map(y->type)) {
|
} else if (is_type_map(rhs_type)) {
|
||||||
Type *key = base_type(y->type)->Map.key;
|
Type *key = base_type(rhs_type)->Map.key;
|
||||||
check_expr_with_type_hint(c, x, be->left, key);
|
check_expr_with_type_hint(c, x, be->left, key);
|
||||||
} else {
|
} else {
|
||||||
check_expr(c, x, be->left);
|
check_expr(c, x, be->left);
|
||||||
@@ -2620,8 +2621,8 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_type_map(y->type)) {
|
if (is_type_map(rhs_type)) {
|
||||||
Type *yt = base_type(y->type);
|
Type *yt = base_type(rhs_type);
|
||||||
if (op.kind == Token_in) {
|
if (op.kind == Token_in) {
|
||||||
check_assignment(c, x, yt->Map.key, str_lit("map 'in'"));
|
check_assignment(c, x, yt->Map.key, str_lit("map 'in'"));
|
||||||
} else {
|
} else {
|
||||||
@@ -2629,8 +2630,8 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint
|
|||||||
}
|
}
|
||||||
|
|
||||||
add_package_dependency(c, "runtime", "__dynamic_map_get");
|
add_package_dependency(c, "runtime", "__dynamic_map_get");
|
||||||
} else if (is_type_bit_set(y->type)) {
|
} else if (is_type_bit_set(rhs_type)) {
|
||||||
Type *yt = base_type(y->type);
|
Type *yt = base_type(rhs_type);
|
||||||
|
|
||||||
if (op.kind == Token_in) {
|
if (op.kind == Token_in) {
|
||||||
check_assignment(c, x, yt->BitSet.elem, str_lit("bit_set 'in'"));
|
check_assignment(c, x, yt->BitSet.elem, str_lit("bit_set 'in'"));
|
||||||
@@ -2679,6 +2680,7 @@ void check_binary_expr(CheckerContext *c, Operand *x, Ast *node, Type *type_hint
|
|||||||
x->expr = node;
|
x->expr = node;
|
||||||
|
|
||||||
return;
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
default:
|
default:
|
||||||
if (is_ise_expr(be->left)) {
|
if (is_ise_expr(be->left)) {
|
||||||
|
|||||||
+2
-1
@@ -1884,7 +1884,8 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
|
|||||||
error(operand.expr, "Cannot iterate over '%s' of type '%s'", s, t);
|
error(operand.expr, "Cannot iterate over '%s' of type '%s'", s, t);
|
||||||
|
|
||||||
if (rs->vals.count == 1) {
|
if (rs->vals.count == 1) {
|
||||||
if (is_type_map(operand.type) || is_type_bit_set(operand.type)) {
|
Type *t = type_deref(operand.type);
|
||||||
|
if (is_type_map(t) || is_type_bit_set(t)) {
|
||||||
gbString v = expr_to_string(rs->vals[0]);
|
gbString v = expr_to_string(rs->vals[0]);
|
||||||
defer (gb_string_free(v));
|
defer (gb_string_free(v));
|
||||||
error_line("\tSuggestion: place parentheses around the expression\n");
|
error_line("\tSuggestion: place parentheses around the expression\n");
|
||||||
|
|||||||
@@ -7753,6 +7753,11 @@ lbValue lb_build_binary_expr(lbProcedure *p, Ast *expr) {
|
|||||||
Type *type = default_type(tv.type);
|
Type *type = default_type(tv.type);
|
||||||
lbValue right = lb_build_expr(p, be->right);
|
lbValue right = lb_build_expr(p, be->right);
|
||||||
Type *rt = base_type(right.type);
|
Type *rt = base_type(right.type);
|
||||||
|
if (is_type_pointer(rt)) {
|
||||||
|
right = lb_emit_load(p, right);
|
||||||
|
rt = type_deref(rt);
|
||||||
|
}
|
||||||
|
|
||||||
switch (rt->kind) {
|
switch (rt->kind) {
|
||||||
case Type_Map:
|
case Type_Map:
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user