checker: fix missing map float key duplicated checking (fix #25098) (#25117)

This commit is contained in:
Felipe Pena 2025-08-16 20:05:02 -03:00 committed by GitHub
parent 74ae8870e8
commit 460b48a33e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 32 additions and 0 deletions

View File

@ -5293,6 +5293,15 @@ fn (mut c Checker) check_dup_keys(node &ast.MapInit, i int) {
}
}
}
} else if key_i is ast.FloatLiteral {
for j in 0 .. i {
key_j := node.keys[j]
if key_j is ast.FloatLiteral {
if key_i.val.f64() == key_j.val.f64() {
c.error('duplicate key "${key_i.val}" in map literal', key_i.pos)
}
}
}
}
}

View File

@ -0,0 +1,14 @@
vlib/v/checker/tests/map_repeated_float_key_err.vv:5:3: error: duplicate key "1.e-06" in map literal
3 | 0.000001: 'small-1'
4 | 0.00001: 'small-2'
5 | 1.e-06: 'small-3'
| ~~~~~~
6 | 0.00001: 'small-4'
7 | }
vlib/v/checker/tests/map_repeated_float_key_err.vv:6:3: error: duplicate key "0.00001" in map literal
4 | 0.00001: 'small-2'
5 | 1.e-06: 'small-3'
6 | 0.00001: 'small-4'
| ~~~~~~~
7 | }
8 | dump(m64)

View File

@ -0,0 +1,9 @@
fn main() {
m64 := {
0.000001: 'small-1'
0.00001: 'small-2'
1.e-06: 'small-3'
0.00001: 'small-4'
}
dump(m64)
}