diff options
Diffstat (limited to 'src/check_stmt.cpp')
| -rw-r--r-- | src/check_stmt.cpp | 28 |
1 files changed, 26 insertions, 2 deletions
diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 388a64e00..bdfa24460 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -402,6 +402,12 @@ gb_internal Type *check_assignment_variable(CheckerContext *ctx, Operand *lhs, O Type *assignment_type = lhs->type; + if (rhs->mode == Addressing_Type && is_type_polymorphic(rhs->type)) { + gbString t = type_to_string(rhs->type); + error(rhs->expr, "Invalid use of a non-specialized polymorphic type '%s'", t); + gb_string_free(t); + } + switch (lhs->mode) { case Addressing_Invalid: return nullptr; @@ -1455,6 +1461,7 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) bool is_map = false; bool use_by_reference_for_value = false; bool is_soa = false; + bool is_reverse = rs->reverse; Ast *expr = unparen_expr(rs->expr); @@ -1470,6 +1477,10 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) } array_add(&vals, x.type); array_add(&vals, t_int); + + if (is_reverse) { + error(node, "#reverse for is not supported with ranges, prefer an explicit for loop with init, condition, and post arguments"); + } } else { Operand operand = {Addressing_Invalid}; check_expr_base(ctx, &operand, expr, nullptr); @@ -1482,6 +1493,9 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) gb_string_free(t); goto skip_expr_range_stmt; } else { + if (is_reverse) { + error(node, "#reverse for is not supported for enum types"); + } array_add(&vals, operand.type); array_add(&vals, t_int); add_type_info_type(ctx, operand.type); @@ -1495,7 +1509,11 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) if (is_type_string(t) && t->Basic.kind != Basic_cstring) { array_add(&vals, t_rune); array_add(&vals, t_int); - add_package_dependency(ctx, "runtime", "string_decode_rune"); + if (is_reverse) { + add_package_dependency(ctx, "runtime", "string_decode_last_rune"); + } else { + add_package_dependency(ctx, "runtime", "string_decode_rune"); + } } break; @@ -1528,6 +1546,9 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) is_map = true; array_add(&vals, t->Map.key); array_add(&vals, t->Map.value); + if (is_reverse) { + error(node, "#reverse for is not supported for map types, as maps are unordered"); + } break; case Type_Tuple: @@ -1564,6 +1585,9 @@ gb_internal void check_range_stmt(CheckerContext *ctx, Ast *node, u32 mod_flags) break; } + if (is_reverse) { + error(node, "#reverse for is not supported for multiple return valued parameters"); + } } break; @@ -2170,7 +2194,7 @@ gb_internal void check_return_stmt(CheckerContext *ctx, Ast *node) { auto operands = array_make<Operand>(heap_allocator(), 0, 2*rs->results.count); defer (array_free(&operands)); - check_unpack_arguments(ctx, result_entities, result_count, &operands, rs->results, true, false); + check_unpack_arguments(ctx, result_entities, result_count, &operands, rs->results, UnpackFlag_AllowOk); if (result_count == 0 && rs->results.count > 0) { error(rs->results[0], "No return values expected"); |