Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow same named types and functions #839

Merged
merged 2 commits into from
Jan 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion soroban-sdk-macros/src/derive_enum.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk-macros/src/derive_enum_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk-macros/src/derive_error_enum_int.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk-macros/src/derive_fn.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk-macros/src/derive_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk-macros/src/derive_struct_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions soroban-sdk/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/contract_add_i32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down
27 changes: 27 additions & 0 deletions soroban-sdk/src/tests/contract_overlapping_type_fn_names.rs
Original file line number Diff line number Diff line change
@@ -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 });
}
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/contract_udt_struct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down
2 changes: 1 addition & 1 deletion soroban-sdk/src/tests/contract_udt_struct_tuple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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![
Expand Down