File tree Expand file tree Collapse file tree 2 files changed +29
-5
lines changed
Expand file tree Collapse file tree 2 files changed +29
-5
lines changed Original file line number Diff line number Diff 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 ( )
Original file line number Diff line number Diff 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 } )
You can’t perform that action at this time.
0 commit comments