Skip to content

declare_program! fails to parse an IDL where an instruction name contains an underscore followed by a number #4281

@Joimer

Description

@Joimer

Description

When trying to cargo build, given an example instruction named initialize_with_token_2022, it will fail with a message similar to:

unresolved import `super`
could not find `__cpi_client_accounts_initialize_with_token_2022` in `internal`

This seems to be due to the underscore being lost when converted to camel case (ie. ::client::args::InitializeWithToken2022) and then back to snake case, where the resulting module would be __cpi_client_accounts_initialize_with_token2022 instead of __cpi_client_accounts_initialize_with_token_2022.

Reproduction

Example IDL: https://solscan.io/account/LanMV9sAd7wArD4vJFi2qDdfnVhFxYSUg6eADduJ3uj#programIdl
Attempt to use the declare_program! macro with the IDL that contains that instruction name.

Solutions and workaround

Since the discriminator is already specified, I fixed this by changing the instruction name to initialize_with_token2022 on the IDL. A solution would be to avoid converting from camel case into snake_case, as it's always ambiguous whether a number was separated by an from a word or not, another solution would be to always eliminate spaces between numbers and letters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions