-
Notifications
You must be signed in to change notification settings - Fork 67
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
Fix contractimport for custom discriminants (#834) #835
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like this PR adds Copy
to all types of contract types, however I think we need to limit it to contracttype
on integer enums, and contracterror
types.
What's the recommended work around here? It just seems very odd/unintuitive that you could explicitly declare: #[contracttype]
#[derive(Copy, Clone, Eq, PartialEq)]
pub enum MapElement {
Asteroid,
FuelPod,
} and yet when getting the bindings from the wasm it's: #[soroban_sdk::contracttype(export = false)]
#[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd)]
pub enum MapElement {
Asteroid,
FuelPod,
} |
Only enums with integer values need the Copy derive. See the examples here: https://soroban.stellar.org/docs/how-to-guides/custom-types#custom-type-enum Specifically: #[contracttype]
#[derive(Clone, Debug, Eq, PartialEq)]
pub enum Enum {
A,
B(...),
} #[contracttype]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
#[repr(u32)]
pub enum Enum {
A = 1,
B = 2,
} |
I think @tyvdh's question might've been misleading here, as it is only loosely connected to the issue at hand. As this seems to be only loosely connected to this issue / PR it might be suitable to open a new issue. |
Another possibility could be to throw a compiler warning when trying to derive |
Ah yes, indeed. The contract specification doesn't capture third party trait implementations. We could extend the contract specification to try and capture other things like that. Something worth considering, although not without tradeoffs. |
I updated the PR to only add the Copy derive in the For my own understanding, I have one question regarding the Spec.
in a rust sense both of these are |
What
Add the
Copy
trait to derived custom types when usingcontractimport
Why
Close #834.
Known limitations
This should not expose any issues as Integer Variant Enums as described in the docs should derive
Clone
anyhow.