Skip to content

Conversation

@crusso
Copy link
Contributor

@crusso crusso commented Sep 22, 2025

(Implement Martin's revised deserialization for Candid options.)

This PR fixes coercion of values into nested optional types.

Before the fix from this PR, 5 : nat64 would coerce to opt 5 : opt na64 (as expected) and null : opt opt nat64 (unexpected). >This PR fixes the unexpected result to be opt opt 5 : opt opt nat64 (as expected).

Before the fix from this PR, 5 : int would coerce to null : opt opt nat. This PR fixes the result to be opt null : opt opt nat. The >motivation for this change is to enable using optional types as follows:

  • outer option characterizes if a value (of any type) is provided;
  • inner option expresses to optimistically deserialize the actual value into the given type (without failing to deserialize and without losing the information if a value of any type is provided).

This PR also adds multiple test cases covering the change to coercion (including coercion to nested optional types over null and reserved).

c.f.

[ ] TODO bump candid dependency to pick up revised test suite

@crusso crusso changed the title repro for issue #5504 test: repro for issue #5504 Sep 22, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Sep 22, 2025

Comparing from bee6787 to 82ce6de:
The produced WebAssembly code seems to be completely unchanged.
In terms of gas, no changes are observed in 5 tests.
In terms of size, no changes are observed in 5 tests.

@crusso crusso changed the title test: repro for issue #5504 fix: repro for issue #5504 Sep 22, 2025
@crusso crusso changed the title fix: repro for issue #5504 fix: repro and fix for issue #5504 Sep 22, 2025
@crusso crusso changed the title fix: repro and fix for issue #5504 experiment: repro and fix for issue #5504 Sep 22, 2025
Copy link

@mraszyk mraszyk left a comment

Choose a reason for hiding this comment

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

Would it be possible to make the tests more compact (and better readable) using generics (analogously to the Rust tests)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants