fix(candid_parser): emit Float32 for Candid float32 in Motoko binding#728
Merged
Conversation
Previously, the Motoko binding generator panicked with "float32 not supported in Motoko" when encountering a `float32` type. This was correct per the spec at the time, but Motoko added `Float32` support in version 1.4.0 (caffeinelabs/motoko#5906), updating both the import and export mappings. The spec has now been updated accordingly. Adds a test fixture (float.did) covering float32/float64 round-trip methods to prevent regression. Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Click to see raw report |
There was a problem hiding this comment.
Pull request overview
This PR updates the Motoko binding generator in candid_parser to support Candid float32 by emitting Motoko’s Float32 type (instead of panicking), and adds a golden test fixture to lock in the expected outputs across all binding targets.
Changes:
- Motoko binding: map Candid
float32to MotokoFloat32instead of panicking at runtime. - Add
float.didtest fixture + corresponding golden outputs (.did,.mo,.rs,.js,.d.ts) to coverfloat32/float64method signatures. - Document the change in
CHANGELOG.mdunder Unreleased.
Reviewed changes
Copilot reviewed 7 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| rust/candid_parser/src/bindings/motoko.rs | Stops panicking on float32 and emits Float32 in generated Motoko bindings. |
| rust/candid_parser/tests/assets/float.did | Adds a new input fixture exercising float32/float64 usage in a service. |
| rust/candid_parser/tests/assets/ok/float.did | Golden pretty-printed .did output for the new fixture. |
| rust/candid_parser/tests/assets/ok/float.mo | Golden Motoko binding output verifying Float32 emission. |
| rust/candid_parser/tests/assets/ok/float.rs | Golden Rust binding output for the new fixture. |
| rust/candid_parser/tests/assets/ok/float.js | Golden JS binding output covering IDL.Float32/IDL.Float64. |
| rust/candid_parser/tests/assets/ok/float.d.ts | Golden TS declaration output for the new fixture. |
| CHANGELOG.md | Notes the Motoko float32 binding bug fix under Unreleased. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Float32 for Candid float32 in Motoko binding
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.
Summary
panic!("float32 not supported in Motoko")withstr("Float32")in the Motoko binding generator.float.didtest fixture coveringfloat32/float64round-trip methods.Why
Motoko added
Float32in version 1.4.0 (dfinity/motoko#5906), updating both the import and export IDL mappings. The spec (design/IDL-Motoko.md) is being updated in a companion PR. This bringsdidc bind --target moin line with whatmocalready does when importing.didfiles directly.Concretely, any
.didfile usingfloat32(e.g. the IC management canister interface) would previously causedidc bind --target moto panic at runtime.