Browse Source

With `-vet-style`, give suggestion of separating where clauses with a comma rather than '&&'

This improves the error messages
gingerBill 1 year ago
parent
commit
f54977336b
3 changed files with 16 additions and 2 deletions
  1. 14 0
      src/check_expr.cpp
  2. 1 1
      src/check_type.cpp
  3. 1 1
      src/parser.cpp

+ 14 - 0
src/check_expr.cpp

@@ -6193,6 +6193,20 @@ gb_internal bool evaluate_where_clauses(CheckerContext *ctx, Ast *call_expr, Sco
 				}
 				}
 				return false;
 				return false;
 			}
 			}
+
+			if (ast_file_vet_style(ctx->file)) {
+				Ast *c = unparen_expr(clause);
+				if (c->kind == Ast_BinaryExpr && c->BinaryExpr.op.kind == Token_CmpAnd) {
+					ERROR_BLOCK();
+					error(c, "Prefer to separate 'where' clauses with a comma rather than '&&'");
+					gbString x = expr_to_string(c->BinaryExpr.left);
+					gbString y = expr_to_string(c->BinaryExpr.right);
+					error_line("\tSuggestion: '%s, %s'", x, y);
+					gb_string_free(y);
+					gb_string_free(x);
+				}
+			}
+
 		}
 		}
 	}
 	}
 
 

+ 1 - 1
src/check_type.cpp

@@ -1166,7 +1166,7 @@ gb_internal void check_bit_field_type(CheckerContext *ctx, Type *bit_field_type,
 				}
 				}
 			}
 			}
 			if (all_ones && all_booleans) {
 			if (all_ones && all_booleans) {
-				if (build_context.vet_flags & VetFlag_Style) {
+				if (ast_file_vet_style(ctx->file)) {
 					char const *msg = "This 'bit_field' is better expressed as a 'bit_set' since all of the fields are booleans, of 1-bit in size, and the backing type is an integer (-vet-style)";
 					char const *msg = "This 'bit_field' is better expressed as a 'bit_set' since all of the fields are booleans, of 1-bit in size, and the backing type is an integer (-vet-style)";
 					error(node, msg);
 					error(node, msg);
 				} else {
 				} else {

+ 1 - 1
src/parser.cpp

@@ -1,7 +1,7 @@
 #include "parser_pos.cpp"
 #include "parser_pos.cpp"
 
 
 gb_internal u64 ast_file_vet_flags(AstFile *f) {
 gb_internal u64 ast_file_vet_flags(AstFile *f) {
-	if (f->vet_flags_set) {
+	if (f != nullptr && f->vet_flags_set) {
 		return f->vet_flags;
 		return f->vet_flags;
 	}
 	}
 	return build_context.vet_flags;
 	return build_context.vet_flags;