Skip to content
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

IDL generation fails on arrays where the size is an associated constant #2286

Closed
EquilateralDelta opened this issue Nov 25, 2022 · 4 comments
Labels
bug Something isn't working idl related to the IDL, either program or client side

Comments

@EquilateralDelta
Copy link

Checked with anchor-cli 0.24.2

const B: usize = 4;

#[account]
pub struct A {
    pub works: [(); 4],
    pub also_works: [(); B],
    pub does_not_work: [(); A::C],
}

impl A {
    const C: usize = 4;
}

In the case of the code below, anchor build successfully builds a contract, but on the IDL generation step build fails with

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: ParseIntError { kind: InvalidDigit }', lang/syn/src/idl/mod.rs:204:76

If the field of does_not_work is commented out, everything works.

@Henry-E
Copy link

Henry-E commented Dec 7, 2022

I feel like this is a known issue. Maybe the IDL generation needs to do a better job at correctly accessing constants but not entirely sure what the solution looks like tbh.

@Henry-E Henry-E added bug Something isn't working bug or feature? and removed bug Something isn't working labels Dec 7, 2022
@EquilateralDelta
Copy link
Author

I think it's not a critical problem to rewrite a code to use a regular constant instead of an associated one, but it can be very confusing for someone to find the culprit of this error. As a suggestion, maybe giving more meta information about a struct and field that causes IDL generation to fail would help locate a problem much more easily.

@Henry-E
Copy link

Henry-E commented Dec 20, 2022

While fixing and improving IDL related generation stuff is a probably the number 3 anchor priority for me, I don't quite know when I'll be able to get to this. In the meantime PRs are welcome or maybe someone else more familiar with the IDL code could look into it.

@acheroncrypto acheroncrypto mentioned this issue Feb 25, 2024
@acheroncrypto acheroncrypto added bug Something isn't working idl related to the IDL, either program or client side and removed bug or feature? labels Mar 10, 2024
@acheroncrypto
Copy link
Collaborator

Fixed by #2824.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working idl related to the IDL, either program or client side
Projects
None yet
Development

No branches or pull requests

3 participants