Fix trait method call resolution in contractimpl - #1729
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes #[contractimpl] macro-generated WASM exports for trait impl blocks so they reliably call the intended trait function (rather than an inherent function with the same name) by switching to UFCS (<Type as Trait>::func).
Changes:
- Update macro function-call generation to use UFCS when
#[contractimpl]is applied toimpl Trait for Type. - Add a regression test exercising a trait/inherent name collision and asserting the trait method is called.
- Add a corresponding test snapshot and register the new test module.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
soroban-sdk-macros/src/derive_fn.rs |
Generates UFCS calls for trait impl exports to fix Rust name-resolution behavior. |
soroban-sdk/src/tests/contractimpl_trait_call_resolution.rs |
Adds regression test for trait vs inherent associated function call resolution. |
soroban-sdk/src/tests.rs |
Registers the new test module. |
soroban-sdk/test_snapshots/tests/contractimpl_trait_call_resolution/calls_trait_fn.1.json |
Adds the expected snapshot output for the new regression test. |
leighmcculloch
enabled auto-merge
February 13, 2026 07:55
mootz12
approved these changes
Feb 13, 2026
leighmcculloch
added a commit
that referenced
this pull request
Feb 13, 2026
### What Use fully qualified syntax (`<Type as Trait>::func()`) in macro-generated WASM exports when `#[contractimpl]` is applied to a trait impl block. ### Why Rust's name resolution prefers inherent methods over trait methods when using `<Type>::func()` syntax. If a contract type has both an inherent method and a trait method with the same name, the generated export incorrectly calls the inherent method instead of the trait method the `#[contractimpl]` block is defined for. (cherry picked from commit e92a393)
leighmcculloch
added a commit
that referenced
this pull request
Feb 13, 2026
### What Use fully qualified syntax (`<Type as Trait>::func()`) in macro-generated WASM exports when `#[contractimpl]` is applied to a trait impl block. ### Why Rust's name resolution prefers inherent methods over trait methods when using `<Type>::func()` syntax. If a contract type has both an inherent method and a trait method with the same name, the generated export incorrectly calls the inherent method instead of the trait method the `#[contractimpl]` block is defined for. (cherry picked from commit e92a393) (cherry picked from commit 347f711)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
What
Use fully qualified syntax (
<Type as Trait>::func()) in macro-generated WASM exports when#[contractimpl]is applied to a trait impl block.Why
Rust's name resolution prefers inherent methods over trait methods when using
<Type>::func()syntax. If a contract type has both an inherent method and a trait method with the same name, the generated export incorrectly calls the inherent method instead of the trait method the#[contractimpl]block is defined for.