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

lang: Fix constant bytes declarations when using declare_program! #3287

Conversation

acheroncrypto
Copy link
Collaborator

Problem

Declaring a bytes constant:

#[constant]
pub const MY_CONST: &[u8] = &[1, 2, 3, 4];

generates the following constants section in the IDL:

"constants": [
    {
      "name": "MY_BYTES",
      "type": "bytes",
      "value": "[1, 2, 3, 4]"
    }
]

Using this IDL with declare_program! panics with:

error: proc macro panicked
 --> programs/my-program/src/lib.rs:9:1
  |
9 | declare_program!(some_program);
  | ^^^^^^^^^^^^^^^^^^^^^
  |
  = help: message: called `Result::unwrap()` on an `Err` value: Error("unexpected end of input, expected expression")

Initially reported in the Anchor Discord server.

Summary of changes

Fix constant bytes declarations when using declare_program! by handling constants that have the type IdlType::Bytes separately.

Copy link

vercel bot commented Sep 30, 2024

@acheroncrypto is attempting to deploy a commit to the coral-xyz Team on Vercel.

A member of the Team first needs to authorize it.

@acheroncrypto acheroncrypto added lang fix Bug fix PR labels Sep 30, 2024
@acheroncrypto acheroncrypto merged commit 143893f into coral-xyz:master Sep 30, 2024
0 of 9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix PR lang
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant