Skip to content

Commit

Permalink
Fixes impl self duplicated missing error. (#6493)
Browse files Browse the repository at this point in the history
## Description

While inserting trait implementations into the trait map we now compare
the implementing type_id without matching UnkownGenerics trait
constraints. Matching the trait constraints was causing a missing error.

Fixes #6381

## Checklist

- [ ] I have linked to any relevant issues.
- [x] I have commented my code, particularly in hard-to-understand
areas.
- [ ] 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.

Co-authored-by: IGI-111 <[email protected]>
  • Loading branch information
esdrubal and IGI-111 authored Sep 3, 2024
1 parent 8cb7796 commit 253330d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 1 deletion.
5 changes: 4 additions & 1 deletion sway-core/src/type_system/unify/unify_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,10 @@ impl<'a> UnifyCheck<'a> {
parent: _,
is_from_type_parameter: _,
},
) => rtc.eq(ltc, &PartialEqWithEnginesContext::new(self.engines)),
) => {
matches!(self.mode, NonGenericConstraintSubset)
|| rtc.eq(ltc, &PartialEqWithEnginesContext::new(self.engines))
}

// any type can be coerced into a generic,
// except if the type already contains the generic
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[package]]
name = "core"
source = "path+from-root-7EB1B3610F4F66A3"

[[package]]
name = "impl_self_duplicated"
source = "member"
dependencies = ["core"]
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
entry = "main.sw"
implicit-std = false
license = "Apache-2.0"
name = "impl_self_duplicated"

[dependencies]
core = { path = "../../../../../../sway-lib-core" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
script;
trait Cat {
fn speak(self) -> u64;
}
trait Dog {
fn speak(self) -> u64;
}
struct S<T> {
x: T,
}
impl<T> S<T>
where
T: Cat,
{
fn foo(self) -> u64 {
self.x.speak() + 1
}
}
impl<T> S<T>
where
T: Dog,
{
fn foo(self) -> u64 {
self.x.speak() + 2
}
}
impl Dog for u64 {
fn speak(self) -> u64 {
2
}
}
impl Cat for u64 {
fn speak(self) -> u64 {
1
}
}
fn main() -> u64 {
let s = S::<u64> { x: 1 };
s.foo();

42
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
category = "fail"
validate_abi = false
expected_warnings = 3

# check: fn foo(self) -> u64 {
# nextln: $()Duplicate definitions for the method "foo" for type "S<T>".

0 comments on commit 253330d

Please sign in to comment.