Browse Source

Improve error message with suggestion for #1866

gingerBill 3 years ago
parent
commit
ea42613fec
2 changed files with 26 additions and 6 deletions
  1. 20 1
      src/check_stmt.cpp
  2. 6 5
      src/types.cpp

+ 20 - 1
src/check_stmt.cpp

@@ -2142,7 +2142,26 @@ void check_stmt_internal(CheckerContext *ctx, Ast *node, u32 flags) {
 			}
 			}
 
 
 			if (new_name_count == 0) {
 			if (new_name_count == 0) {
-				error(node, "No new declarations on the lhs");
+				begin_error_block();
+				error(node, "No new declarations on the left hand side");
+				bool all_underscore = true;
+				for_array(i, vd->names) {
+					Ast *name = vd->names[i];
+					if (name->kind == Ast_Ident) {
+						if (!is_blank_ident(name)) {
+							all_underscore = false;
+							break;
+						}
+					} else {
+						all_underscore = false;
+						break;
+					}
+				}
+				if (all_underscore) {
+					error_line("\tSuggestion: Try changing the declaration (:=) to an assignment (=)\n");
+				}
+
+				end_error_block();
 			}
 			}
 
 
 			Type *init_type = nullptr;
 			Type *init_type = nullptr;

+ 6 - 5
src/types.cpp

@@ -724,10 +724,11 @@ gb_global RecursiveMutex g_type_mutex;
 
 
 struct TypePath;
 struct TypePath;
 
 
-i64      type_size_of         (Type *t);
-i64      type_align_of        (Type *t);
-i64      type_offset_of       (Type *t, i32 index);
-gbString type_to_string       (Type *type, bool shorthand=false);
+i64      type_size_of   (Type *t);
+i64      type_align_of  (Type *t);
+i64      type_offset_of (Type *t, i32 index);
+gbString type_to_string (Type *type, bool shorthand=true);
+gbString type_to_string (Type *type, gbAllocator allocator, bool shorthand=true);
 i64      type_size_of_internal(Type *t, TypePath *path);
 i64      type_size_of_internal(Type *t, TypePath *path);
 void     init_map_internal_types(Type *type);
 void     init_map_internal_types(Type *type);
 Type *   bit_set_to_int(Type *t);
 Type *   bit_set_to_int(Type *t);
@@ -4287,7 +4288,7 @@ gbString write_type_to_string(gbString str, Type *type, bool shorthand=false) {
 }
 }
 
 
 
 
-gbString type_to_string(Type *type, gbAllocator allocator, bool shorthand=false) {
+gbString type_to_string(Type *type, gbAllocator allocator, bool shorthand) {
 	return write_type_to_string(gb_string_make(allocator, ""), type, shorthand);
 	return write_type_to_string(gb_string_make(allocator, ""), type, shorthand);
 }
 }
 gbString type_to_string(Type *type, bool shorthand) {
 gbString type_to_string(Type *type, bool shorthand) {