You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Enums with different reprs are all treated as u8 repr when the frontend loads the account data using anchor-ts, due to the repr information are not included in the IDL file.
The error message is also very confusing as it contains minimal information about the root cause of the bug: Anchor is trying to parse the enum as u8 but due to the size difference of different reprs, Anchor reads data from wrong places and gets an unexpected variant.
P.S. the stack trace is inaccurate as well, which makes debugging anchor errors very unpleasant.
The text was updated successfully, but these errors were encountered:
I encountered this issue when storing an array of enums with zero copy account. In my case, even though the program writes for example Bar::A to the second index, the anchor-ts can only understand first index, everything else is parsed as Bar::None (in another words, the first variant with discriminant of 0).
#[derive(Accounts)]structEndpoint<'info>{foo:AccountLoader<'info,Foo>}#[account(zero_copy)]structFoo{// .. other fieldsbar:[10;Bar],// ... other fields}enumBar{None,A{ inner: .. },// if inner is not repr(packed), then the anchor-ts incorrectly calculates layout sizeB{ inner: .. },Never{padding:[u8;N]}// is this safe to do with zero copy?}
Also, the representation for my enum has layout with a span of -1 if that is relevant:
Enums with different reprs are all treated as u8 repr when the frontend loads the account data using anchor-ts, due to the repr information are not included in the IDL file.
The error message is also very confusing as it contains minimal information about the root cause of the bug: Anchor is trying to parse the enum as u8 but due to the size difference of different reprs, Anchor reads data from wrong places and gets an unexpected variant.
P.S. the stack trace is inaccurate as well, which makes debugging anchor errors very unpleasant.
The text was updated successfully, but these errors were encountered: