diff --git a/sway-core/src/language/ty/ast_node.rs b/sway-core/src/language/ty/ast_node.rs index 99b651a21b9..3d17dd0f441 100644 --- a/sway-core/src/language/ty/ast_node.rs +++ b/sway-core/src/language/ty/ast_node.rs @@ -92,6 +92,9 @@ impl ReplaceDecls for TyAstNode { TyAstNodeContent::ImplicitReturnExpression(ref mut exp) => { exp.replace_decls(decl_mapping, engines) } + TyAstNodeContent::Declaration(TyDecl::VariableDecl(ref mut decl)) => { + decl.body.replace_decls(decl_mapping, engines); + } TyAstNodeContent::Declaration(_) => {} TyAstNodeContent::Expression(ref mut expr) => expr.replace_decls(decl_mapping, engines), TyAstNodeContent::SideEffect(_) => (), diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/Forc.lock new file mode 100644 index 00000000000..3c33721a828 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = 'core' +source = 'path+from-root-B5A424CFF35B4F1C' + +[[package]] +name = 'generic_where_in_impl_self2' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'std' +source = 'path+from-root-B5A424CFF35B4F1C' +dependencies = ['core'] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/Forc.toml new file mode 100644 index 00000000000..e818c8d4916 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "generic_where_in_impl_self2" + +[dependencies] +std = { path = "../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/json_abi_oracle.json new file mode 100644 index 00000000000..03b2f150939 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/json_abi_oracle.json @@ -0,0 +1,25 @@ +{ + "configurables": [], + "functions": [ + { + "attributes": null, + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "messagesTypes": [], + "types": [ + { + "components": null, + "type": "bool", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/src/main.sw new file mode 100644 index 00000000000..2c8bcd21a0a --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/src/main.sw @@ -0,0 +1,36 @@ +script; + +use std::assert::*; + +trait Trait { + #[inline(never)] + fn method(self) -> u64; +} + +impl Trait for u64 { + #[inline(never)] + fn method(self) -> u64{ + 42 + } +} + +struct CallTrait {} + +#[inline(never)] +fn call_trait(t: T) -> u64 where T: Trait { + t.method() +} + +impl CallTrait where K: Trait { + pub fn call_trait(self, key: K) -> u64 { + let v = call_trait(key); + v + } +} + +fn main() -> bool { + let _ = call_trait(1); + let ct = CallTrait:: {}; + assert(ct.call_trait(1) == 42); + true +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/test.toml new file mode 100644 index 00000000000..24cd9f3291c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_where_in_impl_self2/test.toml @@ -0,0 +1,3 @@ +category = "run" +expected_result = { action = "return", value = 1 } +validate_abi = true \ No newline at end of file