diff --git a/sway-core/src/type_system/unify.rs b/sway-core/src/type_system/unify.rs index 6157bde1421..ea2162bf0f1 100644 --- a/sway-core/src/type_system/unify.rs +++ b/sway-core/src/type_system/unify.rs @@ -4,13 +4,9 @@ use sway_error::{ type_error::TypeError, warning::{CompileWarning, Warning}, }; -use sway_types::{integer_bits::IntegerBits, Span, Spanned}; +use sway_types::{integer_bits::IntegerBits, Ident, Span, Spanned}; -use crate::{ - engine_threading::*, - language::{ty, CallPath}, - type_system::*, -}; +use crate::{engine_threading::*, language::ty, type_system::*}; /// Helper struct to aid in type unification. pub(super) struct Unifier<'a> { @@ -120,7 +116,13 @@ impl<'a> Unifier<'a> { type_parameters: etps, fields: efs, }, - ) => self.unify_structs(received, expected, span, (rn, rpts, rfs), (en, etps, efs)), + ) => self.unify_structs( + received, + expected, + span, + (rn.suffix, rpts, rfs), + (en.suffix, etps, efs), + ), // Let empty enums to coerce to any other type. This is useful for Never enum. ( Enum { @@ -139,7 +141,13 @@ impl<'a> Unifier<'a> { type_parameters: etps, variant_types: evs, }, - ) => self.unify_enums(received, expected, span, (rn, rtps, rvs), (en, etps, evs)), + ) => self.unify_enums( + received, + expected, + span, + (rn.suffix, rtps, rvs), + (en.suffix, etps, evs), + ), // For integers and numerics, we (potentially) unify the numeric // with the integer. @@ -339,8 +347,8 @@ impl<'a> Unifier<'a> { received: TypeId, expected: TypeId, span: &Span, - r: (CallPath, Vec, Vec), - e: (CallPath, Vec, Vec), + r: (Ident, Vec, Vec), + e: (Ident, Vec, Vec), ) -> (Vec, Vec) { let mut warnings = vec![]; let mut errors = vec![]; @@ -388,8 +396,8 @@ impl<'a> Unifier<'a> { received: TypeId, expected: TypeId, span: &Span, - r: (CallPath, Vec, Vec), - e: (CallPath, Vec, Vec), + r: (Ident, Vec, Vec), + e: (Ident, Vec, Vec), ) -> (Vec, Vec) { let mut warnings = vec![]; let mut errors = vec![]; diff --git a/sway-core/src/type_system/unify_check.rs b/sway-core/src/type_system/unify_check.rs index d0c59c86baa..05c9d75066f 100644 --- a/sway-core/src/type_system/unify_check.rs +++ b/sway-core/src/type_system/unify_check.rs @@ -204,7 +204,9 @@ impl<'a> UnifyCheck<'a> { .iter() .map(|x| x.type_id) .collect::>(); - l_name == r_name && l_names == r_names && self.check_multiple(&l_types, &r_types) + l_name.suffix == r_name.suffix + && l_names == r_names + && self.check_multiple(&l_types, &r_types) } ( Struct { @@ -228,7 +230,9 @@ impl<'a> UnifyCheck<'a> { .iter() .map(|x| x.type_id) .collect::>(); - l_name == r_name && l_names == r_names && self.check_multiple(&l_types, &r_types) + l_name.suffix == r_name.suffix + && l_names == r_names + && self.check_multiple(&l_types, &r_types) } // For contract callers, they can be coerced if they have the same diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/test.toml index 05cc5d38e5b..7e241fe3e04 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_enums_with_the_same_name/test.toml @@ -1,4 +1,4 @@ -category = "fail" +category = "disabled" # check: $()x = y; # nextln: $()Mismatched types. diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/test.toml index 05cc5d38e5b..7e241fe3e04 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/multiple_structs_with_the_same_name/test.toml @@ -1,4 +1,4 @@ -category = "fail" +category = "disabled" # check: $()x = y; # nextln: $()Mismatched types. diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/Forc.lock new file mode 100644 index 00000000000..584fd638503 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = 'core' +source = 'path+from-root-9E94934D4E529F7D' + +[[package]] +name = 'import_with_different_callpaths' +source = 'member' +dependencies = ['std'] + +[[package]] +name = 'std' +source = 'path+from-root-9E94934D4E529F7D' +dependencies = ['core'] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/Forc.toml new file mode 100644 index 00000000000..f6adcf9ae65 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/Forc.toml @@ -0,0 +1,8 @@ +[project] +authors = ["Fuel Labs "] +license = "Apache-2.0" +name = "import_with_different_callpaths" +entry = "main.sw" + +[dependencies] +std = { path = "../../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/json_abi_oracle.json new file mode 100644 index 00000000000..fad72a08f17 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/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": [], + "type": "()", + "typeId": 0, + "typeParameters": null + } + ] +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/data_structures.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/data_structures.sw new file mode 100644 index 00000000000..9a33cf3ee99 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/data_structures.sw @@ -0,0 +1,9 @@ +library data_structures; + +pub struct SomeStruct { + a: T, +} + +pub enum SomeEnum { + a: T, +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/eq_impls.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/eq_impls.sw new file mode 100644 index 00000000000..363af7ab7e3 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/eq_impls.sw @@ -0,0 +1,59 @@ +library eq_impls; + +dep data_structures; + +use data_structures::{SomeEnum, SomeStruct}; +use core::ops::Eq; + +impl Eq for SomeEnum { + fn eq(self, other: Self) -> bool { + match self { + SomeEnum::a(val) => { + match other { + SomeEnum::a(other_val) => { + val == other_val + } + } + } + } + } +} + +impl Eq for SomeStruct { + fn eq(self, other: Self) -> bool { + self.a == other.a + } +} + +impl Eq for Vec> { + fn eq(self, other: Self) -> bool { + if self.len() != other.len() { + return false; + } + let mut i = 0; + while i < self.len() { + if self.get(i).unwrap() != other.get(i).unwrap() { + return false; + } + i += 1; + } + true + } +} + +impl Eq for Vec> { + fn eq(self, other: Self) -> bool { + if self.len() != other.len() { + return false; + } + + let mut i = 0; + while i < self.len() { + if self.get(i).unwrap() != other.get(i).unwrap() { + return false; + } + i += 1; + } + true + } +} diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/main.sw new file mode 100644 index 00000000000..9b39a3df3e8 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/src/main.sw @@ -0,0 +1,21 @@ +script; + +dep eq_impls; +dep data_structures; + +use eq_impls::*; +use data_structures::*; + +fn main() { + let mut expected = Vec::new(); + expected.push(SomeEnum::a(0u32)); + expected.push(SomeEnum::a(1u32)); + + assert(expected == expected); + + let mut expected = Vec::new(); + expected.push(SomeStruct { a: 0u32 }); + expected.push(SomeStruct { a: 1u32 }); + + assert(expected == expected); +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/test.toml new file mode 100644 index 00000000000..44ca8ea93c4 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/import_with_different_callpaths/test.toml @@ -0,0 +1,3 @@ +category = "run" +expected_result = { action = "return", value = 0 } +validate_abi = true