diff --git a/vlib/encoding/csv/writer.v b/vlib/encoding/csv/writer.v index a1320efadf..3d447a6fdb 100644 --- a/vlib/encoding/csv/writer.v +++ b/vlib/encoding/csv/writer.v @@ -27,8 +27,8 @@ pub fn (mut w Writer) write(record []string) ?bool { return err_invalid_delim } le := if w.use_crlf { '\r\n' } else { '\n' } - for n, _field in record { - mut field := _field + for n, field_ in record { + mut field := field_ if n > 0 { w.sb.write(w.delimiter.str()) } diff --git a/vlib/net/http/cookie.v b/vlib/net/http/cookie.v index d245779866..1dde3cbc35 100644 --- a/vlib/net/http/cookie.v +++ b/vlib/net/http/cookie.v @@ -153,8 +153,8 @@ pub fn read_cookies(h map[string][]string, filter string) []&Cookie { return [] } mut cookies := []&Cookie{} - for _, _line in lines { - mut line := _line.trim_space() + for _, line_ in lines { + mut line := line_.trim_space() mut part := '' for line.len > 0 { if line.index_any(';') > 0 { diff --git a/vlib/net/http/http.v b/vlib/net/http/http.v index 523e2d9841..6eb6f03324 100644 --- a/vlib/net/http/http.v +++ b/vlib/net/http/http.v @@ -156,9 +156,9 @@ pub fn get_text(url string) string { pub fn url_encode_form_data(data map[string]string) string { mut pieces := []string{} - for _key, _value in data { - key := urllib.query_escape(_key) - value := urllib.query_escape(_value) + for key_, value_ in data { + key := urllib.query_escape(key_) + value := urllib.query_escape(value_) pieces << '$key=$value' } return pieces.join('&') diff --git a/vlib/v/checker/checker.v b/vlib/v/checker/checker.v index 54a09b4818..00a2c0f1c5 100644 --- a/vlib/v/checker/checker.v +++ b/vlib/v/checker/checker.v @@ -1904,6 +1904,12 @@ fn (mut c Checker) stmt(node ast.Stmt) { c.in_for_count++ typ := c.expr(node.cond) typ_idx := typ.idx() + if node.key_var.len > 0 && node.key_var != '_' { + c.check_valid_snake_case(node.key_var, 'variable name', node.pos) + } + if node.val_var.len > 0 && node.val_var != '_' { + c.check_valid_snake_case(node.val_var, 'variable name', node.pos) + } if node.is_range { high_type := c.expr(node.high) high_type_idx := high_type.idx() diff --git a/vlib/v/checker/tests/incorrect_for_in_name_variable.out b/vlib/v/checker/tests/incorrect_for_in_name_variable.out new file mode 100644 index 0000000000..90eafaea47 --- /dev/null +++ b/vlib/v/checker/tests/incorrect_for_in_name_variable.out @@ -0,0 +1,8 @@ +vlib/v/checker/tests/incorrect_for_in_name_variable.v:3:6: error: variable name `_aa` cannot start with `_` + 1 | fn main() { + 2 | a := [1,2,3] + 3 | for _aa in a { + | ~~~ + 4 | println(_aa) + 5 | } + \ No newline at end of file diff --git a/vlib/v/checker/tests/incorrect_for_in_name_variable.vv b/vlib/v/checker/tests/incorrect_for_in_name_variable.vv new file mode 100644 index 0000000000..888fd6021a --- /dev/null +++ b/vlib/v/checker/tests/incorrect_for_in_name_variable.vv @@ -0,0 +1,6 @@ +fn main() { + a := [1,2,3] + for _aa in a { + println(_aa) + } +}