mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
checker: validate loop var names (#5677)
This commit is contained in:
parent
cda9240632
commit
34a24eaa4e
@ -27,8 +27,8 @@ pub fn (mut w Writer) write(record []string) ?bool {
|
|||||||
return err_invalid_delim
|
return err_invalid_delim
|
||||||
}
|
}
|
||||||
le := if w.use_crlf { '\r\n' } else { '\n' }
|
le := if w.use_crlf { '\r\n' } else { '\n' }
|
||||||
for n, _field in record {
|
for n, field_ in record {
|
||||||
mut field := _field
|
mut field := field_
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
w.sb.write(w.delimiter.str())
|
w.sb.write(w.delimiter.str())
|
||||||
}
|
}
|
||||||
|
@ -153,8 +153,8 @@ pub fn read_cookies(h map[string][]string, filter string) []&Cookie {
|
|||||||
return []
|
return []
|
||||||
}
|
}
|
||||||
mut cookies := []&Cookie{}
|
mut cookies := []&Cookie{}
|
||||||
for _, _line in lines {
|
for _, line_ in lines {
|
||||||
mut line := _line.trim_space()
|
mut line := line_.trim_space()
|
||||||
mut part := ''
|
mut part := ''
|
||||||
for line.len > 0 {
|
for line.len > 0 {
|
||||||
if line.index_any(';') > 0 {
|
if line.index_any(';') > 0 {
|
||||||
|
@ -156,9 +156,9 @@ pub fn get_text(url string) string {
|
|||||||
|
|
||||||
pub fn url_encode_form_data(data map[string]string) string {
|
pub fn url_encode_form_data(data map[string]string) string {
|
||||||
mut pieces := []string{}
|
mut pieces := []string{}
|
||||||
for _key, _value in data {
|
for key_, value_ in data {
|
||||||
key := urllib.query_escape(_key)
|
key := urllib.query_escape(key_)
|
||||||
value := urllib.query_escape(_value)
|
value := urllib.query_escape(value_)
|
||||||
pieces << '$key=$value'
|
pieces << '$key=$value'
|
||||||
}
|
}
|
||||||
return pieces.join('&')
|
return pieces.join('&')
|
||||||
|
@ -1904,6 +1904,12 @@ fn (mut c Checker) stmt(node ast.Stmt) {
|
|||||||
c.in_for_count++
|
c.in_for_count++
|
||||||
typ := c.expr(node.cond)
|
typ := c.expr(node.cond)
|
||||||
typ_idx := typ.idx()
|
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 {
|
if node.is_range {
|
||||||
high_type := c.expr(node.high)
|
high_type := c.expr(node.high)
|
||||||
high_type_idx := high_type.idx()
|
high_type_idx := high_type.idx()
|
||||||
|
8
vlib/v/checker/tests/incorrect_for_in_name_variable.out
Normal file
8
vlib/v/checker/tests/incorrect_for_in_name_variable.out
Normal file
@ -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 | }
|
||||||
|
|
6
vlib/v/checker/tests/incorrect_for_in_name_variable.vv
Normal file
6
vlib/v/checker/tests/incorrect_for_in_name_variable.vv
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
fn main() {
|
||||||
|
a := [1,2,3]
|
||||||
|
for _aa in a {
|
||||||
|
println(_aa)
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user