Fix () type mapping from SC_SPEC_TYPE_TUPLE to SC_SPEC_TYPE_VOID in contract specifications #1542
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Rust unit type
()was incorrectly being encoded asSC_SPEC_TYPE_TUPLEinstead ofSC_SPEC_TYPE_VOIDin contract specifications. This affected both function parameters and return types that use the unit type.Problem
When defining a contract function like:
The generated contract specification would incorrectly show:
void_argumentparameter asSC_SPEC_TYPE_TUPLE(empty tuple)SC_SPEC_TYPE_TUPLE(empty tuple)Instead of the expected:
void_argumentparameter asSC_SPEC_TYPE_VOIDSC_SPEC_TYPE_VOIDSolution
Modified the
map_typefunction insoroban-sdk-macros/src/map_type.rsto handle empty tuples as a special case. The fix adds a simple check for empty tuples and returnsScSpecTypeDef::Voidinstead of creating an emptyScSpecTypeTuple:Testing
test_unit_type_should_be_void()confirms()maps toScSpecTypeDef::Voidtest_non_empty_tuple_should_be_tuple()ensures non-empty tuples still work correctlyThe 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.