Skip to content

Commit

Permalink
Merge branch 'master' into kayagokalp/6558
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshuaBatty authored Sep 18, 2024
2 parents d8adef5 + 10a78a7 commit 5b0aea5
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 76 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -465,8 +465,12 @@ jobs:
- uses: Swatinem/rust-cache@v2
- name: Install Forc
run: cargo install --locked --debug --path ./forc
- name: Run Unit Tests
run: forc build --path sway-lib-core && forc test --path sway-lib-core && forc build --path sway-lib-std && forc test --path sway-lib-std && forc build --path test/src/in_language_tests & forc test --path test/src/in_language_tests
- name: Run Core Unit Tests
run: forc build --path sway-lib-core && forc test --path sway-lib-core
- name: Run Std Unit Tests
run: forc build --path sway-lib-std && forc test --path sway-lib-std
- name: Run In Language Unit Tests
run: forc build --path test/src/in_language_tests && forc test --path test/src/in_language_tests

forc-pkg-fuels-deps-check:
runs-on: ubuntu-latest
Expand Down
28 changes: 0 additions & 28 deletions sway-core/src/semantic_analysis/namespace/trait_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,34 +1390,6 @@ impl TraitMap {
) -> Result<(), ErrorEmitted> {
let type_engine = engines.te();

// If the type is generic/placeholder, its definition needs to contains all
// constraints
match &*type_engine.get(type_id) {
TypeInfo::UnknownGeneric {
trait_constraints, ..
} => {
let all = constraints.iter().all(|required| {
trait_constraints.iter().any(|constraint| {
constraint.eq(required, &PartialEqWithEnginesContext::new(engines))
})
});
if all {
return Ok(());
}
}
TypeInfo::Placeholder(p) => {
let all = constraints.iter().all(|required| {
p.trait_constraints.iter().any(|constraint| {
constraint.eq(required, &PartialEqWithEnginesContext::new(engines))
})
});
if all {
return Ok(());
}
}
_ => {}
}

let _decl_engine = engines.de();
let unify_check = UnifyCheck::non_dynamic_equality(engines);

Expand Down
47 changes: 24 additions & 23 deletions sway-lib-std/src/bytes.sw
Original file line number Diff line number Diff line change
Expand Up @@ -927,26 +927,27 @@ impl AbiDecode for Bytes {
}
}

#[test]
fn ok_bytes_buffer_ownership() {
let mut original_array = [1u8, 2u8, 3u8, 4u8];
let slice = raw_slice::from_parts::<u8>(__addr_of(original_array), 4);

// Check Bytes duplicates the original slice
let mut bytes = Bytes::from(slice);
bytes.set(0, 5);
assert(original_array[0] == 1);

// At this point, slice equals [5, 2, 3, 4]
let encoded_slice = encode(bytes);

// `Bytes` should duplicate the underlying buffer,
// so when we write to it, it should not change
// `encoded_slice`
let mut bytes = abi_decode::<Bytes>(encoded_slice);
bytes.set(0, 6);
assert(bytes.get(0) == Some(6));

let mut bytes = abi_decode::<Bytes>(encoded_slice);
assert(bytes.get(0) == Some(5));
}
// TODO: Uncomment when fixed. https://github.com/FuelLabs/sway/issues/6567
// #[test]
// fn ok_bytes_buffer_ownership() {
// let mut original_array = [1u8, 2u8, 3u8, 4u8];
// let slice = raw_slice::from_parts::<u8>(__addr_of(original_array), 4);

// // Check Bytes duplicates the original slice
// let mut bytes = Bytes::from(slice);
// bytes.set(0, 5);
// assert(original_array[0] == 1);

// // At this point, slice equals [5, 2, 3, 4]
// let encoded_slice = encode(bytes);

// // `Bytes` should duplicate the underlying buffer,
// // so when we write to it, it should not change
// // `encoded_slice`
// let mut bytes = abi_decode::<Bytes>(encoded_slice);
// bytes.set(0, 6);
// assert(bytes.get(0) == Some(6));

// let mut bytes = abi_decode::<Bytes>(encoded_slice);
// assert(bytes.get(0) == Some(5));
// }
47 changes: 24 additions & 23 deletions sway-lib-std/src/vec.sw
Original file line number Diff line number Diff line change
Expand Up @@ -705,26 +705,27 @@ impl<T> Iterator for VecIter<T> {
}
}

#[test]
fn ok_vec_buffer_ownership() {
let mut original_array = [1u8, 2u8, 3u8, 4u8];
let slice = raw_slice::from_parts::<u8>(__addr_of(original_array), 4);

// Check Vec duplicates the original slice
let mut bytes = Vec::<u8>::from(slice);
bytes.set(0, 5);
assert(original_array[0] == 1);

// At this point, slice equals [5, 2, 3, 4]
let encoded_slice = encode(bytes);

// `Vec<u8>` should duplicate the underlying buffer,
// so when we write to it, it should not change
// `encoded_slice`
let mut bytes = abi_decode::<Vec<u8>>(encoded_slice);
bytes.set(0, 6);
assert(bytes.get(0) == Some(6));

let mut bytes = abi_decode::<Vec<u8>>(encoded_slice);
assert(bytes.get(0) == Some(5));
}
// TODO: Uncomment when fixed. https://github.com/FuelLabs/sway/issues/6567
// #[test]
// fn ok_vec_buffer_ownership() {
// let mut original_array = [1u8, 2u8, 3u8, 4u8];
// let slice = raw_slice::from_parts::<u8>(__addr_of(original_array), 4);

// // Check Vec duplicates the original slice
// let mut bytes = Vec::<u8>::from(slice);
// bytes.set(0, 5);
// assert(original_array[0] == 1);

// // At this point, slice equals [5, 2, 3, 4]
// let encoded_slice = encode(bytes);

// // `Vec<u8>` should duplicate the underlying buffer,
// // so when we write to it, it should not change
// // `encoded_slice`
// let mut bytes = abi_decode::<Vec<u8>>(encoded_slice);
// bytes.set(0, 6);
// assert(bytes.get(0) == Some(6));

// let mut bytes = abi_decode::<Vec<u8>>(encoded_slice);
// assert(bytes.get(0) == Some(5));
// }
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[[package]]
name = "method_missing_constraint"
source = "member"
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
license = "Apache-2.0"
name = "method_missing_constraint"
entry = "main.sw"
implicit-std = false
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[]
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
script;

trait T1 {}
trait T2 {}
struct S<T> where T: T1 {
x: T,
}
impl<T> S<T> where T: T1{
fn only_t1(self) {
Self::also_t2(self);
}
fn also_t2(self) where T: T2{
}
}
impl T1 for u8 {}
impl T1 for u64 {}
impl T2 for u64 {}
fn main() {
let a = S::<u8>{x: 42};
a.only_t1(); //prints Hello but u8 doesn't implement T2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
category = "fail"

# check: $()Self::also_t2(self);
# nextln: $()Trait "T2" is not implemented for type "T".

0 comments on commit 5b0aea5

Please sign in to comment.