Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reapply second pass for metadata types #6568

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,18 @@ pub(crate) fn type_check_method_application(
let arg_handler = Handler::default();
let arg_opt = ty::TyExpression::type_check(&arg_handler, ctx, arg).ok();

let needs_second_pass = arg_handler.has_errors();
// Check this type needs a second pass
let has_errors = arg_handler.has_errors();
let is_not_concrete = arg_opt
.as_ref()
.map(|x| {
x.return_type
.extract_inner_types(engines, IncludeSelf::Yes)
.iter()
.any(|x| !x.is_concrete(engines, TreatNumericAs::Abstract))
})
.unwrap_or_default();
let needs_second_pass = has_errors || is_not_concrete;

if index == 0 {
// We want to emit errors in the self parameter and ignore TraitConstraintNotSatisfied with Placeholder
Expand Down
47 changes: 23 additions & 24 deletions sway-lib-std/src/bytes.sw
Original file line number Diff line number Diff line change
Expand Up @@ -927,27 +927,26 @@ impl AbiDecode for Bytes {
}
}

// 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));
// }
#[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: 23 additions & 24 deletions sway-lib-std/src/vec.sw
Original file line number Diff line number Diff line change
Expand Up @@ -705,27 +705,26 @@ impl<T> Iterator for VecIter<T> {
}
}

// 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));
// }
#[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));
}
Loading