Skip to content

feat: ic-cdk and ic-cdk-macros v0.20.2 — interpret empty vector as candid encoding of () - #711

Merged
lwshang merged 6 commits into
mainfrom
mraszyk/empty-vec-as-input
Jun 8, 2026
Merged

feat: ic-cdk and ic-cdk-macros v0.20.2 — interpret empty vector as candid encoding of ()#711
lwshang merged 6 commits into
mainfrom
mraszyk/empty-vec-as-input

Conversation

@mraszyk

@mraszyk mraszyk commented Jun 8, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes the CDK macros for update, query, init, and post_upgrade methods to interpret an empty input vector as the Candid encoding of () even if the method has a non-empty argument list. The motivation is to allow passing an empty input vector to method taking optional arguments and have them be decoded to None by default.

This PR also releases ic-cdk and ic-cdk-macros v0.20.2 (version bumps in the workspace + crate manifests and the corresponding ic-cdk CHANGELOG entry).

How Has This Been Tested?

New integration tests have been introduced.

Checklist:

  • The title of this PR complies with Conventional Commits.
  • I have edited the CHANGELOG accordingly.
  • I have made corresponding changes to the documentation.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR makes the ic-cdk entrypoint macros (update, query, init, post_upgrade) more permissive by treating an empty msg_arg_data() payload (vec![]) as the Candid “no-arguments” encoding, allowing methods with optional parameters to decode missing inputs as None.

Changes:

  • Adjust macro-generated argument decoding to treat an empty input blob as Candid-encoded “no args” (()), even when the method signature expects arguments.
  • Add end-to-end coverage to ensure vec![] is accepted for methods taking Option<...> arguments (update + query).
  • Document the behavior change in the ic-cdk changelog.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
ic-cdk/CHANGELOG.md Documents the new empty-input decoding behavior for entry points.
ic-cdk-macros/src/export.rs Implements the empty-input-as-() decoding behavior in macro output (and updates macro expansion tests).
e2e-tests/tests/macros.rs Adds integration assertions that empty binary input is accepted for optional-arg methods.
e2e-tests/src/bin/macros/main.rs Introduces foo_update / foo_query canister methods (with Option<u64> args) used by the new e2e test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread ic-cdk-macros/src/export.rs Outdated
Comment thread ic-cdk-macros/src/export.rs Outdated
Comment thread ic-cdk-macros/src/export.rs Outdated
Comment thread ic-cdk-macros/src/export.rs Outdated
@mraszyk
mraszyk marked this pull request as ready for review June 8, 2026 15:14
@mraszyk
mraszyk requested a review from a team as a code owner June 8, 2026 15:14
lwshang and others added 3 commits June 8, 2026 11:25
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Decode the empty-input args from a &[u8] slice pointing at the static
Candid header (DIDL\0\0) instead of allocating a Vec<u8> on every call
with empty input. Addresses Copilot review feedback on #711.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@lwshang lwshang changed the title feat: interpret empty vector as candid encoding of () feat: ic-cdk and ic-cdk-macros v0.20.2 — interpret empty vector as candid encoding of () Jun 8, 2026
@lwshang
lwshang enabled auto-merge (squash) June 8, 2026 15:44
@lwshang
lwshang merged commit 0deb077 into main Jun 8, 2026
18 checks passed
@lwshang
lwshang deleted the mraszyk/empty-vec-as-input branch June 8, 2026 15:48
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