-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
calling map.clear() fails to change the receiver map, in such a way that it has the exact same observable behaviour as doing m = {}
for some maps
#22148
Labels
Bug
This tag is applied to issues which reports bugs.
Modules: builtin
Bugs and problems, concerning the builtin types in V - array, maps, strings, runes.
Comments
spytheman
added
Bug
This tag is applied to issues which reports bugs.
Modules: builtin
Bugs and problems, concerning the builtin types in V - array, maps, strings, runes.
labels
Sep 1, 2024
spytheman
changed the title
calling map.clear() fails to have the exact same observable behaviour to
calling map.clear() fails to change the receiver map, in such a way that it has the exact same observable behaviour as doing Sep 1, 2024
m = {}
for some mapsm = {}
for some maps
Note: this specific combination of keys, was discovered, after running the randomized test described in #22146 for ~1 hour. |
More keys that can lead to the same or similar problem, can be found by running this program: import rand
fn get_random_numbers() []int {
mut res := []int{}
n := rand.u32n(50) or { 5 }
for _ in 0 .. n {
x := rand.intn(100) or { 0 }
// if x == 0 { continue } // filtering out the 0 key, makes failures much less likely (sorted keys *with 0*, are also much less likely to fail)
res << x
}
// return res.sorted() // sorting reduces the chances of a `new.len != clr.len` *a lot*
return res
}
fn random_keys_with_map_clear(iteration int) {
t := get_random_numbers()
mut clr := map[int]int{}
for i in 0 .. 256 {
mut new := map[int]int{}
clr.clear()
for e in t {
new[e] = e
clr[e] = e
if new.len != clr.len {
println('# new.len == ${new.len:3} != clr.len == ${clr.len:3} \n i: ${i:4} e: ${e:4} | t.len: ${t.len:3}, t: ${t}')
return
}
}
if new != clr {
println('# new != clr \n i: ${i:4} | t.len: ${t.len:3}, t: ${t}')
return
}
}
}
fn main() {
for i := 0; i < 999_999_999; i++ {
if 0 == i % 10000 {
println('##### iteration: ${i}')
}
random_keys_with_map_clear(i)
}
} (preferably with |
For example:
|
This is also an interesting one, since the maps should be the same, but
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Bug
This tag is applied to issues which reports bugs.
Modules: builtin
Bugs and problems, concerning the builtin types in V - array, maps, strings, runes.
V doctor:
What did you do?
./v -g -o vdbg cmd/v && ./vdbg x_test.v
What did you expect to see?
a passing test
What did you see instead?
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.
The text was updated successfully, but these errors were encountered: