Skip to content

Fix trait method call resolution in contractimpl - #1729

Merged
leighmcculloch merged 3 commits into
mainfrom
internal6
Feb 13, 2026
Merged

Fix trait method call resolution in contractimpl#1729
leighmcculloch merged 3 commits into
mainfrom
internal6

Conversation

@leighmcculloch

@leighmcculloch leighmcculloch commented Feb 13, 2026

Copy link
Copy Markdown
Member

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.

@leighmcculloch
leighmcculloch requested review from a team, dmkozh and graydon February 13, 2026 07:47
@leighmcculloch
leighmcculloch marked this pull request as ready for review February 13, 2026 07:49
Copilot AI review requested due to automatic review settings February 13, 2026 07:49

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to impl 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.

Comment thread soroban-sdk-macros/src/derive_fn.rs
@leighmcculloch
leighmcculloch added this pull request to the merge queue 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)
Merged via the queue into main with commit e92a393 Feb 13, 2026
92 of 95 checks passed
@leighmcculloch
leighmcculloch deleted the internal6 branch February 13, 2026 14:39
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.

3 participants