Skip to content

Commit e4672e3

Browse files
authored
Fix trait-bound method lookup ambiguity (#7397)
This PR improves the compiler's method-resolution step so trait bounds are actually honoured when we call `T::method()`. Before this change we kept every trait method in scope and emitted a "multiple applicable items" error even when the generic bound singled out one trait. Now we capture which trait each candidate comes from, derive the active trait obligations, and filter the list before picking a candidate. Ambiguity is still reported for real conflicts, but constrained calls now resolve cleanly instead of failing. Also improves the ambiguous trait hint diagnostic to prefer generic type names when emitting the "Multiple applicable items in scope" diagnostic. ## Checklist - [x] I have linked to any relevant issues. - [x] I have commented my code, particularly in hard-to-understand areas. - [x] I have updated the documentation where relevant (API docs, the reference, and the Sway book). - [ ] If my change requires substantial documentation changes, I have [requested support from the DevRel team](https://github.com/FuelLabs/devrel-requests/issues/new/choose) - [x] I have added tests that prove my fix is effective or that my feature works. - [x] I have added (or requested a maintainer to add) the necessary `Breaking*` or `New Feature` labels where relevant. - [x] I have done my best to ensure that my PR adheres to [the Fuel Labs Code Review Standards](https://github.com/FuelLabs/rfcs/blob/master/text/code-standards/external-contributors.md). - [x] I have requested a review from the relevant team or maintainers.
1 parent 6553dce commit e4672e3

File tree

10 files changed

+586
-33
lines changed

10 files changed

+586
-33
lines changed

sway-core/src/semantic_analysis/namespace/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ pub(crate) use trait_map::IsImplInterfaceSurface;
2222
pub(crate) use trait_map::IsImplSelf;
2323
pub(super) use trait_map::ResolvedTraitImplItem;
2424
pub(crate) use trait_map::TraitEntry;
25+
pub(crate) use trait_map::TraitKey;
2526
pub use trait_map::TraitMap;
27+
pub(crate) use trait_map::TraitSuffix;
2628
pub use trait_map::TryInsertingTraitImplOnFailure;
2729

2830
use sway_types::Ident;

0 commit comments

Comments
 (0)