fix: SystemAccount compilation error in #[derive(Accounts)] macro (#3696) #3752
+31
−0
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.
Problem
Using
SystemAccount<'info>
as a field in a struct with#[derive(Accounts)]
was causing compilation errors:Reproduction case:
Root Cause
The issue occurred in
lang/syn/src/lib.rs
in thefrom_account_info
method:try_from
methods that take only one parameter (AccountInfo
)_
case which generates code for two parameters#container_ty::try_from(#owner_addr, &#field)
container_ty()
returnsquote! {}
(empty), making this:::try_from(owner_addr, &field)
❌SystemAccount::try_from
only accepts:try_from(info: &AccountInfo)
✅Solution
Added specific cases for
SystemAccount
andSigner
in thefrom_account_info
method to generate the correct single-parametertry_from
calls:Testing
✅ Compilation Tests:
cargo build --workspace --exclude anchor-cli
- SUCCESStests/system-accounts
program builds (has existing SystemAccount usage)tests/misc
program builds (added test case)✅ Validation:
tests/system-accounts/programs/system-accounts/src/lib.rs
already contains the exact failing pattern and now compiles successfully✅ CI Integration:
tests/system-accounts
Files Changed
lang/syn/src/lib.rs
- Core fix: Added specific cases for SystemAccount and Signertests/misc/programs/misc/src/context.rs
- Added test case for SystemAccounttests/misc/programs/misc/src/lib.rs
- Added test handlerBackward Compatibility
✅ Fully backward compatible - no existing code needs to change. This only fixes previously broken SystemAccount usage.
Closes #3696