Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed required trait constraint not being checked #6525

Merged
merged 5 commits into from
Sep 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 0 additions & 28 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,34 +1390,6 @@ impl TraitMap {
) -> Result<(), ErrorEmitted> {
let type_engine = engines.te();

// If the type is generic/placeholder, its definition needs to contains all
// constraints
match &*type_engine.get(type_id) {
TypeInfo::UnknownGeneric {
trait_constraints, ..
} => {
let all = constraints.iter().all(|required| {
trait_constraints.iter().any(|constraint| {
constraint.eq(required, &PartialEqWithEnginesContext::new(engines))
})
});
if all {
return Ok(());
}
}
TypeInfo::Placeholder(p) => {
let all = constraints.iter().all(|required| {
p.trait_constraints.iter().any(|constraint| {
constraint.eq(required, &PartialEqWithEnginesContext::new(engines))
})
});
if all {
return Ok(());
}
}
_ => {}
}

let _decl_engine = engines.de();
let unify_check = UnifyCheck::non_dynamic_equality(engines);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "method_missing_constraint"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <contact@fuel.sh>"]
license = "Apache-2.0"
name = "method_missing_constraint"
entry = "main.sw"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
script;

trait T1 {}
trait T2 {}
struct S<T> where T: T1 {
x: T,
}
impl<T> S<T> where T: T1{
fn only_t1(self) {
Self::also_t2(self);
}
fn also_t2(self) where T: T2{
}
}
impl T1 for u8 {}
impl T1 for u64 {}
impl T2 for u64 {}
fn main() {
let a = S::<u8>{x: 42};
a.only_t1(); //prints Hello but u8 doesn't implement T2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
category = "fail"

# check: $()Self::also_t2(self);
# nextln: $()Trait "T2" is not implemented for type "T".
Loading