Browse Source

idl: Fix instructions with tuple parameters not producing an error (#3294)

acheron 1 year ago
parent
commit
36e336aba0
2 changed files with 12 additions and 5 deletions
  1. 1 0
      CHANGELOG.md
  2. 11 5
      lang/syn/src/idl/program.rs

+ 1 - 0
CHANGELOG.md

@@ -80,6 +80,7 @@ The minor version will be incremented upon a breaking change and the patch versi
 - idl: Log output with `ANCHOR_LOG` on failure and improve build error message ([#3284](https://github.com/coral-xyz/anchor/pull/3284)).
 - lang: Fix constant bytes declarations when using `declare_program!` ([#3287](https://github.com/coral-xyz/anchor/pull/3287)).
 - lang: Fix using non-instruction composite accounts with `declare_program!` ([#3290](https://github.com/coral-xyz/anchor/pull/3290)).
+- idl: Fix instructions with tuple parameters not producing an error([#3294](https://github.com/coral-xyz/anchor/pull/3294)).
 
 ### Breaking
 

+ 11 - 5
lang/syn/src/idl/program.rs

@@ -2,6 +2,7 @@ use anyhow::{anyhow, Result};
 use heck::CamelCase;
 use proc_macro2::TokenStream;
 use quote::{format_ident, quote};
+use syn::spanned::Spanned;
 
 use super::{
     common::{gen_print_section, get_idl_module_path, get_no_docs, get_program_path},
@@ -25,10 +26,10 @@ pub fn gen_idl_print_fn_program(program: &Program) -> TokenStream {
         _ => quote! { vec![] },
     };
 
-    let (instructions, defined) = program
+    let result = program
         .ixs
         .iter()
-        .flat_map(|ix| -> Result<_> {
+        .map(|ix| {
             let name = ix.ident.to_string();
             let name_pascal = format_ident!("{}", name.to_camel_case());
             let ctx_ident = &ix.anchor_ident;
@@ -48,7 +49,8 @@ pub fn gen_idl_print_fn_program(program: &Program) -> TokenStream {
                         Some(docs) if !no_docs => quote! { vec![#(#docs.into()),*] },
                         _ => quote! { vec![] },
                     };
-                    let (ty, defined) = gen_idl_type(&arg.raw_arg.ty, &[])?;
+                    let (ty, defined) = gen_idl_type(&arg.raw_arg.ty, &[])
+                        .map_err(|_| syn::Error::new(arg.raw_arg.ty.span(), "Unsupported type"))?;
 
                     Ok((
                         quote! {
@@ -61,7 +63,7 @@ pub fn gen_idl_print_fn_program(program: &Program) -> TokenStream {
                         defined,
                     ))
                 })
-                .collect::<Result<Vec<_>>>()?
+                .collect::<syn::Result<Vec<_>>>()?
                 .into_iter()
                 .unzip::<_, Vec<_>, Vec<_>, Vec<_>>();
 
@@ -91,7 +93,11 @@ pub fn gen_idl_print_fn_program(program: &Program) -> TokenStream {
                 defined,
             ))
         })
-        .unzip::<_, Vec<_>, Vec<_>, Vec<_>>();
+        .collect::<syn::Result<Vec<_>>>();
+    let (instructions, defined) = match result {
+        Err(e) => return e.into_compile_error(),
+        Ok(v) => v.into_iter().unzip::<_, Vec<_>, Vec<_>, Vec<_>>(),
+    };
     let defined = defined.into_iter().flatten().flatten().collect::<Vec<_>>();
 
     let fn_body = gen_print_section(