From 4c6ca5b4244e01bdad5496d6e1186ee87b21eb03 Mon Sep 17 00:00:00 2001 From: xunilrj Date: Thu, 3 Oct 2024 16:15:09 +0100 Subject: [PATCH 1/2] return type checked trait constraints --- sway-core/src/type_system/ast_elements/type_parameter.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/sway-core/src/type_system/ast_elements/type_parameter.rs b/sway-core/src/type_system/ast_elements/type_parameter.rs index e79a4bfce64..f5a3da2b56e 100644 --- a/sway-core/src/type_system/ast_elements/type_parameter.rs +++ b/sway-core/src/type_system/ast_elements/type_parameter.rs @@ -213,7 +213,7 @@ impl TypeParameter { // Type check trait constraints only after type checking all type parameters. // This is required because a trait constraint may use other type parameters. // Ex: `struct Struct2 where A : MyAdd` - for type_param in &new_type_params { + for type_param in new_type_params.iter_mut() { TypeParameter::type_check_trait_constraints(handler, ctx.by_ref(), type_param)?; } @@ -327,7 +327,7 @@ impl TypeParameter { fn type_check_trait_constraints( handler: &Handler, mut ctx: TypeCheckContext, - type_parameter: &TypeParameter, + type_parameter: &mut TypeParameter, ) -> Result<(), ErrorEmitted> { let type_engine = ctx.engines.te(); @@ -372,6 +372,8 @@ impl TypeParameter { }, ); + type_parameter.trait_constraints = trait_constraints_with_supertraits; + // Insert the trait constraints into the namespace. type_parameter.insert_into_namespace_constraints(handler, ctx.by_ref())?; From 0407765e5f07c8e01d34f479559df22386f00bd0 Mon Sep 17 00:00:00 2001 From: xunilrj Date: Thu, 24 Oct 2024 07:50:43 +0100 Subject: [PATCH 2/2] more tests --- .../generic_where_in_impl_self/src/main.sw | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self/src/main.sw index 4c3e852777f..474043af251 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self/src/main.sw @@ -27,9 +27,27 @@ impl CallTrait where K: Trait { } } +// https://github.com/FuelLabs/sway/issues/6382 +trait Devour { fn eat(t: T); } +struct Brain { } +struct Zombie { } + +impl Devour for Zombie { + fn eat(_b: Brain) { } +} + +fn feed(t: T) where U: Devour { + U::eat(t); +} + fn main() -> bool { let _ = call_trait(1); let ct = CallTrait:: {}; assert(ct.call_trait(1) == 42); + + // https://github.com/FuelLabs/sway/issues/6382 + let b = Brain{}; + feed::(b); + true }