diff --git a/sway-core/src/decl_engine/ref.rs b/sway-core/src/decl_engine/ref.rs index a99ebf98b98..9ad82d72883 100644 --- a/sway-core/src/decl_engine/ref.rs +++ b/sway-core/src/decl_engine/ref.rs @@ -147,19 +147,13 @@ where ctx: &SubstTypesContext, ) -> Option { let decl_engine = ctx.engines.de(); - if type_mapping.source_ids_contains_concrete_type(ctx.engines) - || !decl_engine.get(&self.id).is_concrete(ctx.engines) - { - let mut decl = (*decl_engine.get(&self.id)).clone(); - if decl.subst(type_mapping, ctx).has_changes() { - Some( - decl_engine - .insert(decl, decl_engine.get_parsed_decl_id(&self.id).as_ref()) - .with_parent(decl_engine, self.id.into()), - ) - } else { - None - } + let mut decl = (*decl_engine.get(&self.id)).clone(); + if decl.subst(type_mapping, ctx).has_changes() { + Some( + decl_engine + .insert(decl, decl_engine.get_parsed_decl_id(&self.id).as_ref()) + .with_parent(decl_engine, self.id.into()), + ) } else { None } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_trait_constraints/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_trait_constraints/src/main.sw index 379224f8925..0073e0ea9d7 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_trait_constraints/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_trait_constraints/src/main.sw @@ -58,6 +58,21 @@ impl MyFrom for Struct3 { } } +// call an associated function through generic constraints +pub trait SizeInBytes { + fn size() -> u64; +} + +impl SizeInBytes for u64 { + fn size() -> u64 { + 8 + } +} + +fn call_size() -> u64 where T: SizeInBytes { + T::size() +} + fn main() -> bool { let s1 = Struct {data: 1_u64 }; assert_eq(s1.data.my_add(1,2),3); @@ -72,5 +87,8 @@ fn main() -> bool { let s4: Struct3 = Struct4{data:42}.my_into(); assert_eq(s4.data,42); + // call an associated function through generic constraints + assert_eq(call_size::(), 8); + true } \ No newline at end of file