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: Fix using constant identifiers as generic arguments #3522

Conversation

acheroncrypto
Copy link
Collaborator

Problem

Using constant identifiers as generic arguments results in a compile error during IDL generation as explained in #3520.

This is because constant identifiers are parsed as GenericArgument::Type (rather than GenericArgument::Const) in the syn library, as they are indistinguishable syntactically:

https://github.com/dtolnay/syn/blob/bfa790b8e445dc67b7ab94d75adb1a92d6296c9a/src/path.rs#L113-L114

Summary of changes

Fix being unable to use constant identifiers as generic arguments by parsing generic arguments that look like a constant identifier as IdlGenericArg::Const rather than IdlGenericArg::Type.

Currently this means we check if the identifier is longer than 1 letter and is fully uppercase. It's not perfect, but it should work as expected if the user follows Rust's naming conventions.

Fixes #3520

Copy link

vercel bot commented Jan 28, 2025

@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 idl related to the IDL, either program or client side fix Bug fix PR labels Jan 28, 2025
@acheroncrypto acheroncrypto merged commit 55d74c6 into coral-xyz:master Jan 29, 2025
52 of 53 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 idl related to the IDL, either program or client side
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"expected type, found constant " when using const generics with a const variable
1 participant