fix(lang/syn): allow destructure/wildcard patterns on Context arg#4469
Open
cryptomotifs wants to merge 1 commit into
Open
fix(lang/syn): allow destructure/wildcard patterns on Context arg#4469cryptomotifs wants to merge 1 commit into
cryptomotifs wants to merge 1 commit into
Conversation
Closes otter-sec#3838. `parse_args` rejected any argument whose pattern was not `Pat::Ident`, which silently caused instructions whose `Context` argument used a destructure (`Context { .. }: Context<T>`) or wildcard (`_: Context<T>`) binding to be filtered out of the program's IDL. The error from `parse_args` was swallowed by the `.ok()?` in the iterator that builds the instruction list. Only the type of the Context argument matters for the derive macro (`ctx_accounts_ident` reads the type, not the pattern), so we accept any pattern for the first argument and substitute a synthetic `ctx` identifier. Subsequent (instruction) arguments still require a named identifier, since their names appear in the generated IDL. Repro that previously produced an empty IDL and now produces the correct instruction: #[program] pub mod foobar { use super::*; pub fn initialize(Context { .. }: Context<Initialize>) -> Result<()> { Ok(()) } }
|
@cryptomotifs is attempting to deploy a commit to the Solana Foundation Team on Vercel. A member of the Team first needs to authorize it. |
Collaborator
|
Please add the test to https://github.com/solana-foundation/anchor/blob/master/tests/idl/programs/idl/src/lib.rs |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #3838.
parse_argspreviously rejected any argument whose pattern was notPat::Ident. Combined with.ok()?in the instruction-collection loop, this caused instructions whoseContextargument used a destructure or wildcard pattern to be silently filtered out of the program's IDL — no warning, no error.Examples that previously produced an empty IDL:
Fix
Only the type of the Context argument matters for the derive macro —
ctx_accounts_ident(inparser/program/mod.rs) readspath_ty.ty, never the pattern name. So we now:ctxidentifier when it is not aPat::Ident.Pat::Identfor subsequent (instruction) arguments, since those names appear in the generated IDL and codegen.Diff
lang/syn/src/parser/program/instructions.rs::parse_args— 11 additions, 3 deletions.Test plan
Pat::Identpath).tests/anchor-cli-idlwith a program that usesContext { .. }and assert the IDL contains the instruction. Happy to follow up with a test commit if that placement works.🤖 Generated with Claude Code