diff --git a/soroban-sdk-macros/src/derive_enum.rs b/soroban-sdk-macros/src/derive_enum.rs index 862c01942..ccf142310 100644 --- a/soroban-sdk-macros/src/derive_enum.rs +++ b/soroban-sdk-macros/src/derive_enum.rs @@ -150,7 +150,7 @@ pub fn derive_type_enum( let spec_xdr = spec_entry.to_xdr().unwrap(); let spec_xdr_lit = proc_macro2::Literal::byte_string(spec_xdr.as_slice()); let spec_xdr_len = spec_xdr.len(); - let spec_ident = format_ident!("__SPEC_XDR_{}", enum_ident.to_string().to_uppercase()); + let spec_ident = format_ident!("__SPEC_XDR_TYPE_{}", enum_ident.to_string().to_uppercase()); Some(quote! { #[cfg_attr(target_family = "wasm", link_section = "contractspecv0")] pub static #spec_ident: [u8; #spec_xdr_len] = #enum_ident::spec_xdr(); diff --git a/soroban-sdk-macros/src/derive_enum_int.rs b/soroban-sdk-macros/src/derive_enum_int.rs index 10b27bc0f..c267cf452 100644 --- a/soroban-sdk-macros/src/derive_enum_int.rs +++ b/soroban-sdk-macros/src/derive_enum_int.rs @@ -69,7 +69,7 @@ pub fn derive_type_enum_int( let spec_xdr = spec_entry.to_xdr().unwrap(); let spec_xdr_lit = proc_macro2::Literal::byte_string(spec_xdr.as_slice()); let spec_xdr_len = spec_xdr.len(); - let spec_ident = format_ident!("__SPEC_XDR_{}", enum_ident.to_string().to_uppercase()); + let spec_ident = format_ident!("__SPEC_XDR_TYPE_{}", enum_ident.to_string().to_uppercase()); Some(quote! { #[cfg_attr(target_family = "wasm", link_section = "contractspecv0")] pub static #spec_ident: [u8; #spec_xdr_len] = #enum_ident::spec_xdr(); diff --git a/soroban-sdk-macros/src/derive_error_enum_int.rs b/soroban-sdk-macros/src/derive_error_enum_int.rs index 58911d6bd..aabc7ff20 100644 --- a/soroban-sdk-macros/src/derive_error_enum_int.rs +++ b/soroban-sdk-macros/src/derive_error_enum_int.rs @@ -66,7 +66,7 @@ pub fn derive_type_error_enum_int( let spec_xdr = spec_entry.to_xdr().unwrap(); let spec_xdr_lit = proc_macro2::Literal::byte_string(spec_xdr.as_slice()); let spec_xdr_len = spec_xdr.len(); - let spec_ident = format_ident!("__SPEC_XDR_{}", enum_ident.to_string().to_uppercase()); + let spec_ident = format_ident!("__SPEC_XDR_TYPE_{}", enum_ident.to_string().to_uppercase()); Some(quote! { #[cfg_attr(target_family = "wasm", link_section = "contractspecv0")] pub static #spec_ident: [u8; #spec_xdr_len] = #enum_ident::spec_xdr(); diff --git a/soroban-sdk-macros/src/derive_fn.rs b/soroban-sdk-macros/src/derive_fn.rs index 310a0291f..caf59292f 100644 --- a/soroban-sdk-macros/src/derive_fn.rs +++ b/soroban-sdk-macros/src/derive_fn.rs @@ -168,7 +168,7 @@ pub fn derive_fn( let spec_xdr = spec_entry.to_xdr().unwrap(); let spec_xdr_lit = proc_macro2::Literal::byte_string(spec_xdr.as_slice()); let spec_xdr_len = spec_xdr.len(); - let spec_ident = format_ident!("__SPEC_XDR_{}", ident.to_string().to_uppercase()); + let spec_ident = format_ident!("__SPEC_XDR_FN_{}", ident.to_string().to_uppercase()); let spec_fn_ident = format_ident!("spec_xdr_{}", ident.to_string()); // If errors have occurred, render them instead. diff --git a/soroban-sdk-macros/src/derive_struct.rs b/soroban-sdk-macros/src/derive_struct.rs index 5b3b97c6a..99b804b85 100644 --- a/soroban-sdk-macros/src/derive_struct.rs +++ b/soroban-sdk-macros/src/derive_struct.rs @@ -95,7 +95,7 @@ pub fn derive_type_struct( let spec_xdr = spec_entry.to_xdr().unwrap(); let spec_xdr_lit = proc_macro2::Literal::byte_string(spec_xdr.as_slice()); let spec_xdr_len = spec_xdr.len(); - let spec_ident = format_ident!("__SPEC_XDR_{}", ident.to_string().to_uppercase()); + let spec_ident = format_ident!("__SPEC_XDR_TYPE_{}", ident.to_string().to_uppercase()); Some(quote! { #[cfg_attr(target_family = "wasm", link_section = "contractspecv0")] pub static #spec_ident: [u8; #spec_xdr_len] = #ident::spec_xdr(); diff --git a/soroban-sdk-macros/src/derive_struct_tuple.rs b/soroban-sdk-macros/src/derive_struct_tuple.rs index 87a6d169e..7979406be 100644 --- a/soroban-sdk-macros/src/derive_struct_tuple.rs +++ b/soroban-sdk-macros/src/derive_struct_tuple.rs @@ -83,7 +83,7 @@ pub fn derive_type_struct_tuple( let spec_xdr = spec_entry.to_xdr().unwrap(); let spec_xdr_lit = proc_macro2::Literal::byte_string(spec_xdr.as_slice()); let spec_xdr_len = spec_xdr.len(); - let spec_ident = format_ident!("__SPEC_XDR_{}", ident.to_string().to_uppercase()); + let spec_ident = format_ident!("__SPEC_XDR_TYPE_{}", ident.to_string().to_uppercase()); Some(quote! { #[cfg_attr(target_family = "wasm", link_section = "contractspecv0")] pub static #spec_ident: [u8; #spec_xdr_len] = #ident::spec_xdr(); diff --git a/soroban-sdk/src/tests.rs b/soroban-sdk/src/tests.rs index 760ff9230..8c211d036 100644 --- a/soroban-sdk/src/tests.rs +++ b/soroban-sdk/src/tests.rs @@ -7,6 +7,7 @@ mod contract_call_stack; mod contract_invoke; mod contract_invoker_account; mod contract_invoker_client; +mod contract_overlapping_type_fn_names; mod contract_snapshot; mod contract_store; mod contract_udt_enum; diff --git a/soroban-sdk/src/tests/contract_add_i32.rs b/soroban-sdk/src/tests/contract_add_i32.rs index 47f5cdf2d..b9be74822 100644 --- a/soroban-sdk/src/tests/contract_add_i32.rs +++ b/soroban-sdk/src/tests/contract_add_i32.rs @@ -24,7 +24,7 @@ fn test_functional() { #[test] fn test_spec() { - let entries = ScSpecEntry::from_xdr(__SPEC_XDR_ADD).unwrap(); + let entries = ScSpecEntry::from_xdr(__SPEC_XDR_FN_ADD).unwrap(); let expect = ScSpecEntry::FunctionV0(ScSpecFunctionV0 { name: "add".try_into().unwrap(), inputs: vec![ diff --git a/soroban-sdk/src/tests/contract_overlapping_type_fn_names.rs b/soroban-sdk/src/tests/contract_overlapping_type_fn_names.rs new file mode 100644 index 000000000..844b1d46f --- /dev/null +++ b/soroban-sdk/src/tests/contract_overlapping_type_fn_names.rs @@ -0,0 +1,27 @@ +use crate as soroban_sdk; +use soroban_sdk::{contractimpl, contracttype, Env}; + +#[derive(Copy, Clone, Debug, Eq, PartialEq)] +#[contracttype] +pub struct State { + pub a: i32, +} + +pub struct Contract; + +#[contractimpl] +impl Contract { + pub fn state() -> State { + State { a: 1 } + } +} + +#[test] +fn test_functional() { + let env = Env::default(); + let contract_id = env.register_contract(None, Contract); + + let client = ContractClient::new(&env, &contract_id); + let s = client.state(); + assert_eq!(s, State { a: 1 }); +} diff --git a/soroban-sdk/src/tests/contract_udt_struct.rs b/soroban-sdk/src/tests/contract_udt_struct.rs index e22f231d3..dc3feded8 100644 --- a/soroban-sdk/src/tests/contract_udt_struct.rs +++ b/soroban-sdk/src/tests/contract_udt_struct.rs @@ -59,7 +59,7 @@ fn test_error_on_partial_decode() { #[test] fn test_spec() { - let entries = ScSpecEntry::from_xdr(__SPEC_XDR_ADD).unwrap(); + let entries = ScSpecEntry::from_xdr(__SPEC_XDR_FN_ADD).unwrap(); let expect = ScSpecEntry::FunctionV0(ScSpecFunctionV0 { name: "add".try_into().unwrap(), inputs: vec![ diff --git a/soroban-sdk/src/tests/contract_udt_struct_tuple.rs b/soroban-sdk/src/tests/contract_udt_struct_tuple.rs index 2dcf68250..356f981fe 100644 --- a/soroban-sdk/src/tests/contract_udt_struct_tuple.rs +++ b/soroban-sdk/src/tests/contract_udt_struct_tuple.rs @@ -68,7 +68,7 @@ fn test_error_on_partial_decode() { #[test] fn test_spec() { - let entries = ScSpecEntry::from_xdr(__SPEC_XDR_ADD).unwrap(); + let entries = ScSpecEntry::from_xdr(__SPEC_XDR_FN_ADD).unwrap(); let expect = ScSpecEntry::FunctionV0(ScSpecFunctionV0 { name: "add".try_into().unwrap(), inputs: std::vec![