From 6c2b93d5193f827c86c0cdd5938ceb91a6804397 Mon Sep 17 00:00:00 2001 From: gingerBill Date: Tue, 15 Dec 2020 22:28:40 +0000 Subject: Improve text/scanner whitespace parameter to use a bit_set instead; Improve error message for `for x in y` where y is not iterable but allows `in` as an operator --- src/check_stmt.cpp | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'src/check_stmt.cpp') diff --git a/src/check_stmt.cpp b/src/check_stmt.cpp index 8a41dd12b..117872848 100644 --- a/src/check_stmt.cpp +++ b/src/check_stmt.cpp @@ -1803,9 +1803,19 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) { if (val0 == nullptr) { gbString s = expr_to_string(operand.expr); gbString t = type_to_string(operand.type); + defer (gb_string_free(s)); + defer (gb_string_free(t)); + error(operand.expr, "Cannot iterate over '%s' of type '%s'", s, t); - gb_string_free(t); - gb_string_free(s); + + if (rs->val0 != nullptr && rs->val1 == nullptr) { + if (is_type_map(operand.type) || is_type_bit_set(operand.type)) { + gbString v = expr_to_string(rs->val0); + defer (gb_string_free(v)); + error_line("\tSuggestion: place parentheses around the expression\n"); + error_line("\t for (%s in %s) {\n", v, s); + } + } } } -- cgit v1.2.3