diff --git a/sway-core/src/semantic_analysis/namespace/trait_map.rs b/sway-core/src/semantic_analysis/namespace/trait_map.rs index 0fb87dceaa2..8628d9952a7 100644 --- a/sway-core/src/semantic_analysis/namespace/trait_map.rs +++ b/sway-core/src/semantic_analysis/namespace/trait_map.rs @@ -679,7 +679,10 @@ impl TraitMap { suffix: e.key.name.suffix.name.clone(), is_absolute: e.key.name.is_absolute, }; - if &map_trait_name == trait_name + let are_same_name_traits = (trait_name.prefixes.is_empty() + && map_trait_name.suffix == trait_name.suffix) + || &map_trait_name == trait_name; + if are_same_name_traits && are_equal_minus_dynamic_types(type_engine, type_id, e.key.type_id) { let mut trait_methods = e.value.values().cloned().into_iter().collect::>(); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/Forc.lock new file mode 100644 index 00000000000..0b3da60c883 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = 'core' +source = 'path+from-root-33945E385D757681' + +[[package]] +name = 'eq_custom_type' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'std' +source = 'path+from-root-33945E385D757681' +dependencies = ['core'] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/Forc.toml new file mode 100644 index 00000000000..bd4014260c5 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "eq_custom_type" + +[dependencies] +std = { path = "../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/json_abi_oracle.json new file mode 100644 index 00000000000..563d0f990c4 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/json_abi_oracle.json @@ -0,0 +1,22 @@ +{ + "functions": [ + { + "inputs": [], + "name": "main", + "output": { + "name": "", + "type": 0, + "typeArguments": null + } + } + ], + "loggedTypes": [], + "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/stdlib/eq_custom_type/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/src/main.sw new file mode 100644 index 00000000000..a7bdf20df85 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/src/main.sw @@ -0,0 +1,30 @@ +script; + +use core::ops::*; + +enum Error { + BoolError: bool, + U8Error: u8, +} + +impl Eq for Error { + fn eq(self, other: Self) -> bool { + match (self, other) { + (Error::BoolError(val1), Error::BoolError(val2)) => val2 == val1, + (Error::U8Error(val1), Error::U8Error(val2)) => val2 == val1, + _ => false, + } + } +} + +fn test_none_ok_or(_val: T, default: E) where E: Eq { + match Option::None::().ok_or(default) { + Result::Ok(_) => revert(0), + Result::Err(e) => assert(default == e), + } +} + +fn main() -> bool { + test_none_ok_or(true, Error::BoolError(true)); + return true; +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/test.toml new file mode 100644 index 00000000000..ace9e6f3186 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/stdlib/eq_custom_type/test.toml @@ -0,0 +1,3 @@ +category = "run" +expected_result = { action = "return", value = 1 } +validate_abi = true