diff --git a/sway-core/src/semantic_analysis/cei_pattern_analysis.rs b/sway-core/src/semantic_analysis/cei_pattern_analysis.rs index 3e8acd24dbe..fafcaf6d9cb 100644 --- a/sway-core/src/semantic_analysis/cei_pattern_analysis.rs +++ b/sway-core/src/semantic_analysis/cei_pattern_analysis.rs @@ -515,9 +515,6 @@ fn effects_of_expression(engines: &Engines, expr: &ty::TyExpression) -> HashSet< let type_engine = engines.te(); let decl_engine = engines.de(); match &expr.expression { - ConstGenericExpression { .. } => { - todo!("Will be implemented by https://github.com/FuelLabs/sway/issues/6860") - } Literal(_) | ConstantExpression { .. } | ConfigurableExpression { .. } @@ -525,6 +522,7 @@ fn effects_of_expression(engines: &Engines, expr: &ty::TyExpression) -> HashSet< | FunctionParameter | Break | Continue + | ConstGenericExpression { .. } | AbiName(_) => HashSet::new(), // this type of assignment only mutates local variables and not storage Reassignment(reassgn) => effects_of_expression(engines, &reassgn.rhs), diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_impl_self_where/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_impl_self_where/test.toml index 0c984916317..4ce10cccb80 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_impl_self_where/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/generic_impl_self_where/test.toml @@ -1,6 +1,4 @@ -# TODO Enable this test once https://github.com/FuelLabs/sway/issues/6899 is fixed. -# Compilation fails with error: No method "contains4(Data2, Data2) -> bool" found for type "Data2". -category = "disabled" +category = "run" expected_result = { action = "return", value = 10 } expected_result_new_encoding = { action = "return_data", value = "000000000000000A" } validate_abi = true diff --git a/test/src/in_language_tests/Forc.toml b/test/src/in_language_tests/Forc.toml index afc5ac7c385..6e75fed6a89 100644 --- a/test/src/in_language_tests/Forc.toml +++ b/test/src/in_language_tests/Forc.toml @@ -30,9 +30,7 @@ members = [ "test_programs/result_inline_tests", "test_programs/revert_inline_tests", "test_programs/storage_key_inline_tests", -# TODO: Enable this test once https://github.com/FuelLabs/sway/issues/6899 is fixed. -# Compilation fails with error: No method "eq(Self, Self) -> ()" found for type "Self". -# "test_programs/storage_vec_iter_tests", + "test_programs/storage_vec_iter_tests", "test_programs/string_inline_tests", "test_programs/time_inline_tests", "test_programs/tx_inline_tests", diff --git a/test/src/in_language_tests/test_programs/storage_vec_iter_tests/src/impls.sw b/test/src/in_language_tests/test_programs/storage_vec_iter_tests/src/impls.sw index bb7e364f4e5..f1c0481f15e 100644 --- a/test/src/in_language_tests/test_programs/storage_vec_iter_tests/src/impls.sw +++ b/test/src/in_language_tests/test_programs/storage_vec_iter_tests/src/impls.sw @@ -117,6 +117,7 @@ impl TestInstance for str { } } +#[cfg(experimental_const_generics = false)] impl PartialEq for str[6] { fn eq(self, other: Self) -> bool { let mut i = 0; @@ -134,6 +135,7 @@ impl PartialEq for str[6] { true } } +#[cfg(experimental_const_generics = false)] impl Eq for str[6] {} impl TestInstance for str[6] { @@ -154,11 +156,13 @@ impl TestInstance for str[6] { } } +#[cfg(experimental_const_generics = false)] impl PartialEq for [u64; 2] { fn eq(self, other: Self) -> bool { self[0] == other[0] && self[1] == other[1] } } +#[cfg(experimental_const_generics = false)] impl Eq for [u64; 2] {} impl TestInstance for [u64; 2] { @@ -251,13 +255,6 @@ impl TestInstance for Enum { } } -impl PartialEq for (u8, u32) { - fn eq(self, other: Self) -> bool { - self.0 == other.0 && self.1 == other.1 - } -} -impl Eq for (u8, u32) {} - impl TestInstance for (u8, u32) { fn elements(len: u64) -> Vec { let u8_values = u8::elements(len); @@ -288,16 +285,11 @@ impl TestInstance for b256 { } } -impl AbiEncode for raw_ptr { - fn abi_encode(self, buffer: Buffer) -> Buffer { - let ptr_as_u64 = asm(p: self) { - p: u64 - }; - ptr_as_u64.abi_encode(buffer) - } +pub struct RawPtrNewtype { + ptr: raw_ptr, } -impl TestInstance for raw_ptr { +impl TestInstance for RawPtrNewtype { fn elements(len: u64) -> Vec { let values = u8::elements(len); let mut res = Vec::new(); @@ -306,16 +298,39 @@ impl TestInstance for raw_ptr { let null_ptr = asm() { zero: raw_ptr }; - res.push(null_ptr.add::(values.get(i).unwrap().as_u64())); + res.push(RawPtrNewtype { + ptr: null_ptr.add::(values.get(i).unwrap().as_u64()) + }); i += 1; } res } } +impl AbiEncode for RawPtrNewtype { + fn abi_encode(self, buffer: Buffer) -> Buffer { + let ptr_as_u64 = asm(p: self.ptr) { + p: u64 + }; + ptr_as_u64.abi_encode(buffer) + } +} + +impl PartialEq for RawPtrNewtype { + fn eq(self, other: Self) -> bool { + self.ptr == other.ptr + } +} +impl Eq for RawPtrNewtype {} + impl TestInstance for raw_slice { fn elements(len: u64) -> Vec { - let ptr_values = raw_ptr::elements(len); + let raw_ptr_values = RawPtrNewtype::elements(len); + let mut ptr_values = Vec::::new(); + for raw_ptr in raw_ptr_values.iter() { + ptr_values.push(raw_ptr.ptr); + } + let len_values = u8::elements(len); let mut res = Vec::new(); let mut i = 0; @@ -335,13 +350,6 @@ impl TestInstance for raw_slice { } } -impl PartialEq for raw_slice { - fn eq(self, other: Self) -> bool { - self.ptr() == other.ptr() && self.number_of_bytes() == other.number_of_bytes() - } -} -impl Eq for raw_slice {} - impl TestInstance for () { fn elements(len: u64) -> Vec { let mut res = Vec::new(); @@ -354,13 +362,6 @@ impl TestInstance for () { } } -impl PartialEq for () { - fn eq(self, other: Self) -> bool { - true - } -} -impl Eq for () {} - impl TestInstance for [u64; 0] { fn elements(len: u64) -> Vec { let mut res = Vec::new(); @@ -373,9 +374,11 @@ impl TestInstance for [u64; 0] { } } +#[cfg(experimental_const_generics = false)] impl PartialEq for [u64; 0] { fn eq(self, other: Self) -> bool { true } } +#[cfg(experimental_const_generics = false)] impl Eq for [u64; 0] {} diff --git a/test/src/in_language_tests/test_programs/storage_vec_iter_tests/src/main.sw b/test/src/in_language_tests/test_programs/storage_vec_iter_tests/src/main.sw index 07dcfda5f91..a3d1220fe28 100644 --- a/test/src/in_language_tests/test_programs/storage_vec_iter_tests/src/main.sw +++ b/test/src/in_language_tests/test_programs/storage_vec_iter_tests/src/main.sw @@ -8,23 +8,6 @@ use impls::Enum; use std::hash::{Hash, sha256}; use std::storage::storage_vec::*; -abi StorageVecIterTest { - #[storage(read)] - fn assert_empty_vec_next_returns_none(); - - #[storage(read, write)] - fn assert_vec_with_elements_next_returns_element(); - - #[storage(read, write)] - fn assert_vec_with_elements_for_loop_iteration(); - - #[storage(read, write)] - fn storage_vec_field_for_loop_iteration(); - - #[storage(read, write)] - fn storage_vec_field_nested_for_loop_iteration(); -} - storage { vec: StorageVec = StorageVec {}, vec_of_vec: StorageVec> = StorageVec {}, @@ -33,8 +16,7 @@ storage { #[storage(read)] fn assert_empty_vec_next_returns_none_impl(slot_id_preimage: u64) { let vec: StorageKey> = StorageKey::new(sha256(slot_id_preimage), 0, sha256(slot_id_preimage + 100)); - // TODO: Replace with `.is_none()` method call once https://github.com/FuelLabs/sway/issues/6825 is fixed. - assert(Option::is_none(vec.iter().next())); + assert(vec.iter().next().is_none()); } #[storage(read, write)] @@ -58,8 +40,7 @@ where let mut iter = vec.iter(); while i < NUM_OF_ELEMENTS { let element = iter.next(); - // TODO: Replace with `.is_some()` method call once https://github.com/FuelLabs/sway/issues/6825 is fixed. - assert(Option::is_some(element)); + assert(element.is_some()); let value = element.unwrap().read(); assert_eq(value, vec.get(i).unwrap().read()); @@ -67,11 +48,10 @@ where i += 1; } - // TODO: Replace with `.is_none()` method call once https://github.com/FuelLabs/sway/issues/6825 is fixed. let element_after_last = iter.next(); - assert(Option::is_none(element_after_last)); + assert(element_after_last.is_none()); let element_after_last = iter.next(); - assert(Option::is_none(element_after_last)); + assert(element_after_last.is_none()); } #[storage(read, write)] @@ -91,21 +71,18 @@ where i += 1; } - // TODO: This code fails to compile with the error given below. - // Uncomment this test once https://github.com/FuelLabs/sway/issues/6825 is fixed. - // let mut i = 0; - // for element in vec.iter() { - // // ERROR: ^^^^^^^^^^ No method "unwrap(Option>)" found for type "Option>". - // let value = element.read(); - // assert_eq(value, vec.get(i).unwrap().read()); + let mut i = 0; + for element in vec.iter() { + let value = element.read(); + assert_eq(value, vec.get(i).unwrap().read()); - // i += 1; - // } + i += 1; + } - // assert_eq(vec.len(), i); + assert_eq(vec.len(), i); } -impl StorageVecIterTest for Contract { +impl Contract { #[storage(read)] fn assert_empty_vec_next_returns_none() { assert_empty_vec_next_returns_none_impl::<()>(1); @@ -124,7 +101,7 @@ impl StorageVecIterTest for Contract { assert_empty_vec_next_returns_none_impl::(14); assert_empty_vec_next_returns_none_impl::<(u8, u32)>(15); assert_empty_vec_next_returns_none_impl::(16); - assert_empty_vec_next_returns_none_impl::(17); + assert_empty_vec_next_returns_none_impl::(17); assert_empty_vec_next_returns_none_impl::(18); } @@ -147,7 +124,7 @@ impl StorageVecIterTest for Contract { assert_vec_with_elements_next_returns_element_impl::(14); assert_vec_with_elements_next_returns_element_impl::<(u8, u32)>(15); assert_vec_with_elements_next_returns_element_impl::(16); - assert_vec_with_elements_next_returns_element_impl::(17); + assert_vec_with_elements_next_returns_element_impl::(17); assert_vec_with_elements_next_returns_element_impl::(18); } @@ -170,7 +147,7 @@ impl StorageVecIterTest for Contract { assert_vec_with_elements_for_loop_iteration_impl::(14); assert_vec_with_elements_for_loop_iteration_impl::<(u8, u32)>(15); assert_vec_with_elements_for_loop_iteration_impl::(16); - assert_vec_with_elements_for_loop_iteration_impl::(17); + assert_vec_with_elements_for_loop_iteration_impl::(17); assert_vec_with_elements_for_loop_iteration_impl::(18); } @@ -239,30 +216,30 @@ impl StorageVecIterTest for Contract { #[test] fn empty_vec_next_returns_none() { - let contract_abi = abi(StorageVecIterTest, CONTRACT_ID); + let contract_abi = abi(StorageVecIterTestsAbi, CONTRACT_ID); contract_abi.assert_empty_vec_next_returns_none(); } #[test] fn vec_with_elements_next_returns_element() { - let contract_abi = abi(StorageVecIterTest, CONTRACT_ID); + let contract_abi = abi(StorageVecIterTestsAbi, CONTRACT_ID); contract_abi.assert_vec_with_elements_next_returns_element(); } #[test] fn vec_with_elements_for_loop_iteration() { - let contract_abi = abi(StorageVecIterTest, CONTRACT_ID); + let contract_abi = abi(StorageVecIterTestsAbi, CONTRACT_ID); contract_abi.assert_vec_with_elements_for_loop_iteration(); } #[test] fn storage_vec_field_for_loop_iteration() { - let contract_abi = abi(StorageVecIterTest, CONTRACT_ID); + let contract_abi = abi(StorageVecIterTestsAbi, CONTRACT_ID); contract_abi.storage_vec_field_for_loop_iteration(); } #[test] fn storage_vec_field_nested_for_loop_iteration() { - let contract_abi = abi(StorageVecIterTest, CONTRACT_ID); + let contract_abi = abi(StorageVecIterTestsAbi, CONTRACT_ID); contract_abi.storage_vec_field_nested_for_loop_iteration(); }