Skip to content

Commit

Permalink
ast: fix const map init order (fix #23255) (#23256)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyi98 authored Dec 24, 2024
1 parent 0de5e98 commit 667a07c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
3 changes: 3 additions & 0 deletions vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -2552,6 +2552,9 @@ pub fn (t &Table) dependent_names_in_expr(expr Expr) []string {
names << t.dependent_names_in_expr(expr.right)
}
MapInit {
for key in expr.keys {
names << t.dependent_names_in_expr(key)
}
for val in expr.vals {
names << t.dependent_names_in_expr(val)
}
Expand Down
26 changes: 26 additions & 0 deletions vlib/v/tests/consts/const_map_init_order_test.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const bit = f64(1)
const nibble = bit * 4
const bytes = bit * 8
const kb = bytes * 1000
const mb = kb * 1000

const units_map = {
bit: 'bit'
nibble: 'nibble'
bytes: 'byte'
kb: 'kB'
mb: 'MB'
}

fn test_const_map_init_order() {
println(units_map.len)
println(units_map)
assert units_map.len == 5
assert units_map == {
1.0: 'bit'
4.0: 'nibble'
8.0: 'byte'
8000.0: 'kB'
8.e+06: 'MB'
}
}

0 comments on commit 667a07c

Please sign in to comment.