Skip to content

Commit

Permalink
fix map update syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
felipensp committed Nov 27, 2024
1 parent e03ed74 commit 16dbbbe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions vlib/v/ast/table.v
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ pub mut:
arr_pop bool // arr.pop()
arr_init bool // [1, 2, 3]
arr_map bool // []map[key]value
map_update bool // {...foo}
interpolation bool // '${foo} ${bar}'
option_or_result bool // has panic call
print_types map[int]bool // print() idx types
Expand Down
1 change: 1 addition & 0 deletions vlib/v/checker/containers.v
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,7 @@ fn (mut c Checker) map_init(mut node ast.MapInit) ast.Type {
}

if (node.keys.len > 0 && node.vals.len > 0) || node.has_update_expr {
c.table.used_features.map_update = true
mut map_type := ast.void_type
use_expected_type := c.expected_type != ast.void_type && !c.inside_const
&& c.table.sym(c.expected_type).kind == .map && !(c.inside_fn_arg
Expand Down
5 changes: 5 additions & 0 deletions vlib/v/markused/markused.v
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
core_fns << 'new_array_from_c_array_noscan'
core_fns << '__new_array_with_multi_default'
core_fns << '__new_array_with_multi_default_noscan'
core_fns << '__new_array_with_array_default'
}
if table.used_features.option_or_result {
core_fns << '_option_ok'
Expand All @@ -172,6 +173,10 @@ pub fn mark_used(mut table ast.Table, mut pref_ pref.Preferences, ast_files []&a
core_fns << map_idx_str + '.clone'
table.used_features.used_maps++
}
if table.used_features.map_update {
core_fns << 'new_map_update_init'
table.used_features.used_maps++
}
all_fn_root_names << core_fns
}

Expand Down

0 comments on commit 16dbbbe

Please sign in to comment.