feat: support argument names#612
Merged
Merged
Conversation
luc-blaeser
reviewed
Jun 10, 2025
luc-blaeser
reviewed
Jun 10, 2025
luc-blaeser
reviewed
Jun 10, 2025
luc-blaeser
approved these changes
Jun 10, 2025
luc-blaeser
left a comment
There was a problem hiding this comment.
Very nice PR. Just a few little comments, mostly just questions for my own understanding. Thank you, Luca!
luc-blaeser
approved these changes
Jun 10, 2025
luc-blaeser
left a comment
There was a problem hiding this comment.
Thanks for following up. Ready to merge IMO
Contributor
Author
|
Let's wait for the fixes on the bench tests before merging this PR, cc @mraszyk |
Click to see raw report |
luc-blaeser
reviewed
Jun 11, 2025
| let args = <>; | ||
| let mut named_args: Vec<String> = args.iter().filter_map(|a| a.name.clone()).collect(); | ||
| named_args.sort(); | ||
| check_unique(named_args.iter()).map_err(|e| error(e))?; |
There was a problem hiding this comment.
Just a note for future refactoring, nothing to fix here: Probably the function check_unique should be renamed as it requires sorted input. One could assume that a general unique check works generally on unsorted input.
luc-blaeser
reviewed
Jun 11, 2025
luc-blaeser
reviewed
Jun 11, 2025
luc-blaeser
approved these changes
Jun 11, 2025
luc-blaeser
left a comment
There was a problem hiding this comment.
Nice adjustments, good catch of numbered args case.
lwshang
added a commit
that referenced
this pull request
Jul 25, 2025
…ate (#652) This PR refactors recent changes (#612 and #640) to avoid a major version bump in `candid` crate. > * Breaking changes: > + `pp_args` and `pp_init_args` now require a `&[ArgType]` parameter. The `pp_rets` function has been added, with the signature of the old `pp_args`. > + `pretty::candid::pp_label` now takes a `&Label` parameter, instead of a `&SharedLabel`. The previously altered API (`pp_args`, `pp_init_args`, `pp_label`) has been restored to maintain backward compatibility. The intended new behavior is now exposed via new, non-breaking methods: `pp_named_args`, `pp_named_init_args` and `pp_label_raw`.
Merged
ilbertt
added a commit
that referenced
this pull request
Jul 29, 2025
ilbertt
added a commit
that referenced
this pull request
Jul 29, 2025
ilbertt
added a commit
that referenced
this pull request
Oct 9, 2025
Named arguments can also be in the return type, and can be ignored. This PR restores that was changed in https://github.com/dfinity/candid/pull/612/files#diff-c5ff9610c5d6538ec79f3d465965d2b3a3e3b628b16854a91b4b4a90ba766a57L220-L230, in order to keep parsing the return types with arguments without throwing. Updates a test case to check if the behavior has been restored.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Overview
Adds support for named arguments: if a
.didCandid declaration file declares functions, classes or services with named arguments, those names are parsed by thecandid-parserand preserved in the generated bindings.At the same time, the names of the arguments are preserved if the Candid declaration file is generated from a Rust canister.
Requirements
To consider this feature complete, the Motoko compiler should preserve the actor methods names from Motoko canisters to the Candid declaration files.
Considerations
This change should be backwards compatible.
Picked up from https://github.com/ilbertt/candid/tree/luca/arg-names