#TryFromVal<Env, MyEnum> is not satisfied Build Error

1 messages · Page 1 of 1 (latest)

normal swift
#

Getting a build error when trying to upgrade a contract to 21.1.0-rc.1.

error: enum integer ProposalStatus must have `derive(Copy)`
   --> contracts/governor/src/types.rs:121:10
    |
121 | pub enum ProposalStatus {
    |          ^^^^^^^^^^^^^^

error[E0277]: the trait bound `ProposalStatus: TryFromVal<Env, soroban_sdk::Val>` is not satisfied
  --> contracts/governor/src/types.rs:86:1
   |
86 | #[contracttype]
   | ^^^^^^^^^^^^^^^ the trait `TryFromVal<Env, soroban_sdk::Val>` is not implemented for `ProposalStatus`, which is required by `soroban_sdk::Val: TryIntoVal<_, _>`
   |
   = help: the following other types implement trait `TryFromVal<E, V>`:
             <bool as TryFromVal<Env, bool>>
             <bool as TryFromVal<E, soroban_sdk::Val>>
             <i32 as TryFromVal<Env, i32>>
             <i32 as TryFromVal<E, soroban_sdk::Val>>
             <i64 as TryFromVal<Env, i64>>
             <i64 as TryFromVal<E, soroban_sdk::Val>>
             <i128 as TryFromVal<Env, i128>>
             <i128 as TryFromVal<E, soroban_sdk::Val>>
           and 295 others
   = note: required for `soroban_sdk::Val` to implement `TryIntoVal<Env, ProposalStatus>`
   = note: this error originates in the attribute macro `contracttype` (in Nightly builds, run with -Z macro-backtrace for more info)

Enum in question:

#[derive(Clone, Copy, PartialEq, Eq, Debug)]
#[contracttype]
pub enum ProposalStatus {
    /// The proposal exists and voting has not been closed
    Open = 0,
    /// The proposal was voted for. If the proposal is executable, the timelock begins once this state is reached.
    Successful = 1,
    /// The proposal was voted against
    Defeated = 2,
    /// The proposal did not reach quorum before the voting period ended, or was stalled out during the grace period.
    Expired = 3,
    /// The proposal has been executed
    Executed = 4,
    /// The proposal has been canceled
    Canceled = 5,
}

This builds with 20.5.0. Any suggestions?

white scaffoldBOT
#

Remember you can open a Github issue right here from Discord with the /create command.

worthy hill
#

huh, I suppose it works with v20? or even with a previous v21?

#

ah, sorry, I see now that it used to work with 20.5

white scaffoldBOT
worthy hill
#

@wide pawn , any idea?

quartz oxide
#

(I believe leigh is out for a few weeks. maybe @slender plinth, @bitter current or @full hill can help?)

queen geyser
#

did you try to add the TryFromVal, TryIntoVal into the derive?

#

ea: #[derive(Clone, Copy, PartialEq, Eq, Debug, TryFromVal, TryIntoVal)] (make sure you import them)

#

but ya u shouldnn't need to specify that and it appears to have already tried it. 😄 i haven't tried 21.1 just 21.0

full hill
#

taking a look

full hill
#

I've found out the reason for the derive(Copy) error.
In this release we added a check to the contract enum type, making sure it derives from Copy. This was intended to improve error message, since Copy trait is required for contract client generation which is not obvious to the contract developer.
However the check isn't comprehensive, i.e. it only works if #[contracttype] is above all other attributes (it only parse the tokens after it).
As a short term fix I'm going to revert that change and we'll do another patch release. If you need to get unblocked sooner you can manually move the #[contracttype] around. i.e.

#[contracttype]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum ProposalStatus
#

I wasn't able to reproduce the TryFromVal<E, V> error though, I suspect that is a different issue that has to do with code using the type.

normal swift
#

Sounds good - I’ll give that a shot. Thanks!

full hill
#

btw I am able to produce the TryFromVal error from a different unrelated example, so it likely to be a issue, I just haven't been able to figure it out yet

queen geyser
#

The error implies it doesn't fit into any matching tryfrom but I wasn't able to replicate it. Maybe my contracttype was already in the right place

full hill
#

Ok, my earlier encounter of the TryFromVal error was just due to some Cargo weirdness, not an actual bug (it was resolve after getting the versions straightened out)