浏览代码

Improve warning handling for possible `default:` typo

gingerBill 1 年之前
父节点
当前提交
c54e3d3c4f
共有 1 个文件被更改,包括 6 次插入0 次删除
  1. 6 0
      src/check_stmt.cpp

+ 6 - 0
src/check_stmt.cpp

@@ -2031,6 +2031,12 @@ gb_internal void check_value_decl_stmt(CheckerContext *ctx, Ast *node, u32 mod_f
 			gb_string_free(str);
 			init_type = t_invalid;
 		}
+		if (init_type == t_invalid && entity_count == 1 && (mod_flags & (Stmt_BreakAllowed|Stmt_FallthroughAllowed))) {
+			Entity *e = entities[0];
+			if (e != nullptr && e->token.string == "default") {
+				warning(e->token, "Did you mean 'case:'?");
+			}
+		}
 	}