mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix map_init position (#8293)
This commit is contained in:
parent
749d6133a1
commit
b8857baa98
@ -33,10 +33,10 @@ vlib/v/checker/tests/for_in_mut_val_type.vv:17:15: error: array literal is immut
|
|||||||
| ~~~~~~~~~~
|
| ~~~~~~~~~~
|
||||||
18 | j *= 2
|
18 | j *= 2
|
||||||
19 | }
|
19 | }
|
||||||
vlib/v/checker/tests/for_in_mut_val_type.vv:20:19: error: map literal is immutable, it cannot be changed
|
vlib/v/checker/tests/for_in_mut_val_type.vv:20:18: error: map literal is immutable, it cannot be changed
|
||||||
18 | j *= 2
|
18 | j *= 2
|
||||||
19 | }
|
19 | }
|
||||||
20 | for _, mut j in {'aa': 1, 'bb': 2} {
|
20 | for _, mut j in {'aa': 1, 'bb': 2} {
|
||||||
| ~~~~
|
| ~~~~~~~~~~~~~~~~~~
|
||||||
21 | j *= 2
|
21 | j *= 2
|
||||||
22 | }
|
22 | }
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
vlib/v/checker/tests/map_init_wrong_type.vv:3:10: error: cannot assign to `a`: expected `map[string]f32`, not `map[string]f64`
|
vlib/v/checker/tests/map_init_wrong_type.vv:3:8: error: cannot assign to `a`: expected `map[string]f32`, not `map[string]f64`
|
||||||
1 | fn main() {
|
1 | fn main() {
|
||||||
2 | mut a := map[string]f32{}
|
2 | mut a := map[string]f32{}
|
||||||
3 | a = { 'x': 12.3 }
|
3 | a = { 'x': 12.3 }
|
||||||
| ~~~
|
| ~~~~~~~~~~~~~
|
||||||
4 | _ = {2:0 3:0 "hi":0}
|
4 | _ = {2:0 3:0 "hi":0}
|
||||||
5 | _ = {2:0 3:`@` 4:0}
|
5 | _ = {2:0 3:`@` 4:0}
|
||||||
vlib/v/checker/tests/map_init_wrong_type.vv:4:17: error: invalid map key: expected `int`, not `string`
|
vlib/v/checker/tests/map_init_wrong_type.vv:4:17: error: invalid map key: expected `int`, not `string`
|
||||||
|
@ -151,7 +151,7 @@ fn (mut p Parser) array_init() ast.ArrayInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn (mut p Parser) map_init() ast.MapInit {
|
fn (mut p Parser) map_init() ast.MapInit {
|
||||||
mut pos := p.tok.position()
|
first_pos := p.prev_tok.position()
|
||||||
mut keys := []ast.Expr{}
|
mut keys := []ast.Expr{}
|
||||||
mut vals := []ast.Expr{}
|
mut vals := []ast.Expr{}
|
||||||
for p.tok.kind != .rcbr && p.tok.kind != .eof {
|
for p.tok.kind != .rcbr && p.tok.kind != .eof {
|
||||||
@ -167,10 +167,9 @@ fn (mut p Parser) map_init() ast.MapInit {
|
|||||||
p.next()
|
p.next()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
pos.update_last_line(p.tok.line_nr)
|
|
||||||
return ast.MapInit{
|
return ast.MapInit{
|
||||||
keys: keys
|
keys: keys
|
||||||
vals: vals
|
vals: vals
|
||||||
pos: pos
|
pos: first_pos.extend_with_last_line(p.tok.position(), p.tok.line_nr)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user