Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Aug 19, 2025

The Rust unit type () was incorrectly being encoded as SC_SPEC_TYPE_TUPLE instead of SC_SPEC_TYPE_VOID in contract specifications. This affected both function parameters and return types that use the unit type.

Problem

When defining a contract function like:

#[contractimpl]
impl Contract {
    pub fn void_fn(env: Env, void_argument: ()) -> () {
        void_argument
    }
}

The generated contract specification would incorrectly show:

  • void_argument parameter as SC_SPEC_TYPE_TUPLE (empty tuple)
  • Return type as SC_SPEC_TYPE_TUPLE (empty tuple)

Instead of the expected:

  • void_argument parameter as SC_SPEC_TYPE_VOID
  • Return type as SC_SPEC_TYPE_VOID

Solution

Modified the map_type function in soroban-sdk-macros/src/map_type.rs to handle empty tuples as a special case. The fix adds a simple check for empty tuples and returns ScSpecTypeDef::Void instead of creating an empty ScSpecTypeTuple:

Type::Tuple(TypeTuple { elems, .. }) => {
    // Handle unit type () as ScSpecTypeDef::Void
    if elems.is_empty() {
        return Ok(ScSpecTypeDef::Void);
    }
    // ... existing tuple handling logic for non-empty tuples
}

Testing

  • Added comprehensive unit tests to verify the fix
  • test_unit_type_should_be_void() confirms () maps to ScSpecTypeDef::Void
  • test_non_empty_tuple_should_be_tuple() ensures non-empty tuples still work correctly
  • All existing tests continue to pass (8/8)
  • Integration testing confirms real contract functions work as expected

The fix is minimal and surgical, preserving all existing functionality while correctly handling the unit type case.

Fixes #1215.


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI changed the title [WIP] () is encoded as a SC_SPEC_TYPE_TUPLE instead of SC_SPEC_TYPE_VOID Fix () type mapping from SC_SPEC_TYPE_TUPLE to SC_SPEC_TYPE_VOID in contract specifications Aug 19, 2025
Copilot AI requested a review from anupsdf August 19, 2025 06:07
Copilot finished work on behalf of anupsdf August 19, 2025 06:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

() is encoded as a SC_SPEC_TYPE_TUPLE instead of SC_SPEC_TYPE_VOID

2 participants