1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

builtin: fix m.len to 0, after calling map.clear() (#16720)

This commit is contained in:
yuyi
2022-12-23 03:36:33 +08:00
committed by GitHub
parent f9043c84a7
commit e01dac885c
2 changed files with 43 additions and 0 deletions

View File

@ -993,3 +993,45 @@ fn test_alias_of_map_delete() {
assert m.len == 1
assert m[22] == 222
}
struct State {
mut:
state map[string]rune
}
struct Foo {
bar int
baz int
}
fn (mut st State) add(s string, r rune) {
st.state[s] = r
}
fn (mut st State) add2(foos []Foo) {
for f in foos {
st.state['${f.bar},${f.baz}'] = `z`
}
}
fn (mut st State) reset() {
st.state.clear()
}
fn test_map_clear() {
mut s := State{}
item1 := [Foo{
bar: 1
baz: 2
}, Foo{
bar: 3
baz: 4
}]
s.add2(item1)
assert s.state.len == 2
s.reset()
s.add2(item1)
assert s.state.len == 2
}