mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
parser: fix mutable map args
This commit is contained in:
parent
19c9e226a3
commit
10b0432eca
@ -158,6 +158,16 @@ fn test_string_arr() {
|
|||||||
assert m['a'][1] == 'two'
|
assert m['a'][1] == 'two'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn mut_map(m mut map[string]int) {
|
||||||
|
m['a'] = 10
|
||||||
|
}
|
||||||
|
|
||||||
|
fn test_mut_arg() {
|
||||||
|
mut m := map[string]int
|
||||||
|
mut_map(mut m)
|
||||||
|
assert m['a'] == 10
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
fn test_ref() {
|
fn test_ref() {
|
||||||
m := { 'one': 1 }
|
m := { 'one': 1 }
|
||||||
|
@ -400,7 +400,11 @@ fn (p mut Parser) gen_array_set(typ string, is_ptr, is_map bool,fn_ph, assign_po
|
|||||||
mut cao_tmp := p.cgen.cur_line
|
mut cao_tmp := p.cgen.cur_line
|
||||||
mut func := ''
|
mut func := ''
|
||||||
if is_map {
|
if is_map {
|
||||||
func = 'map_set(&'
|
if is_ptr {
|
||||||
|
func = 'map_set('
|
||||||
|
} else {
|
||||||
|
func = 'map_set(&'
|
||||||
|
}
|
||||||
// CAO on map is a bit more complicated as it loads
|
// CAO on map is a bit more complicated as it loads
|
||||||
// the value inside a pointer instead of returning it.
|
// the value inside a pointer instead of returning it.
|
||||||
}
|
}
|
||||||
|
@ -1831,7 +1831,7 @@ fn (p mut Parser) index_expr(typ_ string, fn_ph int) string {
|
|||||||
if is_indexer {
|
if is_indexer {
|
||||||
is_fixed_arr := typ[0] == `[`
|
is_fixed_arr := typ[0] == `[`
|
||||||
if !is_str && !is_arr && !is_map && !is_ptr && !is_fixed_arr && !is_variadic_arg {
|
if !is_str && !is_arr && !is_map && !is_ptr && !is_fixed_arr && !is_variadic_arg {
|
||||||
p.error('Cant [] non-array/string/map. Got type "$typ"')
|
p.error('invalid operation: type `$typ` does not support indexing')
|
||||||
}
|
}
|
||||||
p.check(.lsbr)
|
p.check(.lsbr)
|
||||||
// Get element type (set `typ` to it)
|
// Get element type (set `typ` to it)
|
||||||
@ -1844,7 +1844,7 @@ fn (p mut Parser) index_expr(typ_ string, fn_ph int) string {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Bounds check everywhere else
|
// Bounds check everywhere else
|
||||||
p.gen(',')
|
p.gen(', ')
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if is_variadic_arg { typ = typ[5..] }
|
if is_variadic_arg { typ = typ[5..] }
|
||||||
@ -1864,8 +1864,8 @@ fn (p mut Parser) index_expr(typ_ string, fn_ph int) string {
|
|||||||
// typ = 'byte'
|
// typ = 'byte'
|
||||||
typ = typ.replace('*', '')
|
typ = typ.replace('*', '')
|
||||||
// modify(mut []string) fix
|
// modify(mut []string) fix
|
||||||
if !is_arr {
|
if !is_arr && !is_map {
|
||||||
p.gen('[/*ptr*/')
|
p.gen('[/*ptr!*/')
|
||||||
close_bracket = true
|
close_bracket = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user