Skip to content

Commit 79e9b73

Browse files
author
Akash Thota
committed
fix: for non #instruction[(..)] accounts
1 parent d7d22a0 commit 79e9b73

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

lang/syn/src/codegen/accounts/try_accounts.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,29 @@ pub fn generate(accs: &AccountsStruct) -> proc_macro2::TokenStream {
116116

117117
// Generate type validation methods for instruction parameters
118118
let type_validation_methods = match &accs.instruction_api {
119-
None => quote! {},
119+
None => {
120+
// generate stub methods for up to 16 possible arguments
121+
let stub_methods: Vec<proc_macro2::TokenStream> = (0..16)
122+
.map(|idx| {
123+
let method_name = syn::Ident::new(
124+
&format!("__anchor_validate_ix_arg_type_{}", idx),
125+
proc_macro2::Span::call_site(),
126+
);
127+
quote! {
128+
#[doc(hidden)]
129+
#[inline(always)]
130+
#[allow(unused)]
131+
pub fn #method_name<T>(_arg: &T) {
132+
// no type validation when #[instruction(...)] is missing
133+
}
134+
}
135+
})
136+
.collect();
137+
138+
quote! {
139+
#(#stub_methods)*
140+
}
141+
}
120142
Some(ix_api) => {
121143
let type_check_methods: Vec<proc_macro2::TokenStream> = ix_api
122144
.iter()

lang/syn/src/codegen/program/handlers.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,12 @@ pub fn generate(program: &Program) -> proc_macro2::TokenStream {
138138
);
139139
quote! {
140140
// Type validation for argument #idx
141-
if false {
142-
// This code is never executed but is type-checked at compile time
143-
let __type_check_arg: #arg_ty = panic!();
144-
#anchor::#method_name(&__type_check_arg);
141+
if #anchor::__ANCHOR_IX_PARAM_COUNT > #idx {
142+
if false {
143+
// This code is never executed but is type-checked at compile time
144+
let __type_check_arg: #arg_ty = panic!();
145+
#anchor::#method_name(&__type_check_arg);
146+
}
145147
}
146148
}
147149
})

0 commit comments

Comments
 (0)