Skip to content
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

v: add map update-init syntax #20561

Merged
merged 4 commits into from
Jan 17, 2024
Merged

Conversation

edam
Copy link
Member

@edam edam commented Jan 17, 2024

Add support for map update-init syntax to v:

foo := {
    ...base_map
    'a': 55
    'b': 66
}

which is functionally equivalent to:

mut foo := base_map.clone()
foo['a'] = 55
foo['b'] = 66

except that it yields an expression which does not have to be mutable.

This PR updates:

  • ast, checker, parser and cgen
  • adds new_map_update_init() to builtin/map.v to support cgen
  • docs
  • v fmt
  • v tests & checker tests

@edam
Copy link
Member Author

edam commented Jan 17, 2024

@spytheman are you able to retry the failing test? It seems unrelated?

@shove70
Copy link
Contributor

shove70 commented Jan 17, 2024

@spytheman are you able to retry the failing test? It seems unrelated?

restarted.

Comment on lines +1510 to +1513
has_update_expr bool // has `...a`
update_expr Expr // `a` in `...a`
update_expr_pos token.Pos
update_expr_comments []Comment
Copy link
Member

@spytheman spytheman Jan 17, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cmd/tools/vast/vast.v:1645 also needs updating, when adding new fields, that can carry meaningful information about the source. v ast -p file.v is very useful, for understanding the AST structure of a file.

Copy link
Member

@spytheman spytheman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent work.

@spytheman spytheman merged commit c4b8036 into vlang:master Jan 17, 2024
54 checks passed
kbkpbot pushed a commit to kbkpbot/v that referenced this pull request Jan 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants