Skip to content

Commit

Permalink
idl: Fix instructions with tuple parameters not producing an error
Browse files Browse the repository at this point in the history
  • Loading branch information
acheroncrypto committed Oct 4, 2024
1 parent 4d06a88 commit 34a72a0
Showing 1 changed file with 11 additions and 5 deletions.
16 changes: 11 additions & 5 deletions lang/syn/src/idl/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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;
Expand All @@ -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! {
Expand All @@ -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<_>>();

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 34a72a0

Please sign in to comment.