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

#[constant] doesn't evaluate const fns. #1560

Closed
sagefarrenholz opened this issue Mar 6, 2022 · 1 comment
Closed

#[constant] doesn't evaluate const fns. #1560

sagefarrenholz opened this issue Mar 6, 2022 · 1 comment
Labels
bug Something isn't working idl related to the IDL, either program or client side

Comments

@sagefarrenholz
Copy link

sagefarrenholz commented Mar 6, 2022

I would like the IDL to include output from constant functions. I am guessing that it doesn't work because the preprocessor runs before constant function evaluation.

What I have:

#[constant]
const AccountSize: usize = size_of::<SomeAccount>();

The IDL looks like:

"constants": [
  {
    "name": "AccountSize",
    "type": {
      "defined": "usize"
    },
    "value": "mem_macros :: size_of ! (SomeAccount)"
  }
],

Is there an idiomatic method to use a constant function in a IDL constant declaration in Anchor?
I also tried switching the size_of::<SomeAccount>(); to a proc macro but it didn't evaluate either, just copying TokenStream into IDL.

@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 labels Mar 10, 2024
@acheroncrypto
Copy link
Collaborator

Fixed in #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

2 participants