Skip to content

Commit 460b48a

Browse files
authored
checker: fix missing map float key duplicated checking (fix #25098) (#25117)
1 parent 74ae887 commit 460b48a

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎vlib/v/checker/checker.v‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5293,6 +5293,15 @@ fn (mut c Checker) check_dup_keys(node &ast.MapInit, i int) {
52935293
}
52945294
}
52955295
}
5296+
} else if key_i is ast.FloatLiteral {
5297+
for j in 0 .. i {
5298+
key_j := node.keys[j]
5299+
if key_j is ast.FloatLiteral {
5300+
if key_i.val.f64() == key_j.val.f64() {
5301+
c.error('duplicate key "${key_i.val}" in map literal', key_i.pos)
5302+
}
5303+
}
5304+
}
52965305
}
52975306
}
52985307

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
vlib/v/checker/tests/map_repeated_float_key_err.vv:5:3: error: duplicate key "1.e-06" in map literal
2+
3 | 0.000001: 'small-1'
3+
4 | 0.00001: 'small-2'
4+
5 | 1.e-06: 'small-3'
5+
| ~~~~~~
6+
6 | 0.00001: 'small-4'
7+
7 | }
8+
vlib/v/checker/tests/map_repeated_float_key_err.vv:6:3: error: duplicate key "0.00001" in map literal
9+
4 | 0.00001: 'small-2'
10+
5 | 1.e-06: 'small-3'
11+
6 | 0.00001: 'small-4'
12+
| ~~~~~~~
13+
7 | }
14+
8 | dump(m64)
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
fn main() {
2+
m64 := {
3+
0.000001: 'small-1'
4+
0.00001: 'small-2'
5+
1.e-06: 'small-3'
6+
0.00001: 'small-4'
7+
}
8+
dump(m64)
9+
}

0 commit comments

Comments
 (0)