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

implement named args #828

Merged
merged 3 commits into from
Mar 21, 2025
Merged

implement named args #828

merged 3 commits into from
Mar 21, 2025

Conversation

metagn
Copy link
Collaborator

@metagn metagn commented Mar 20, 2025

closes #522

When encountering a named argument in a call, sem semchecks its value and passes it along with the name to sigmatch. It is also tracked if a named argument was given, in which case the arguments are reordered before passing to the sigmatch proc.

The way the reordering is done: The signature params are iterated over first to build a table of names to param positions etc. Then the given arguments are iterated over, saving the positions of arguments belonging to each parameter. Then a new list of arguments is built in the order of the parameters. Varargs is considered by saving arguments as "continued", i.e. the parameter position is not advanced for them when building the list. Missing parameters add a dot token to mark a default value, but this does not fail early to behave the same as missing default values in normal matching.

A quirk of original Nim is that positional arguments are not influenced by named arguments before them, i.e. in foo(name1 = val1, name2 = val2, val3, ...), val3 always matches the 3rd parameter of the proc. This behavior is preserved here.

@metagn metagn marked this pull request as ready for review March 20, 2025 09:45
@Araq Araq merged commit ed49a1c into nim-lang:master Mar 21, 2025
3 checks passed
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.

Implement named parameters in calls
2 participants