Skip to content

Commit

Permalink
Merge branch 'master' into ironcev/6796-impl-iterator-for-storage-vec
Browse files Browse the repository at this point in the history
  • Loading branch information
ironcev committed Jan 10, 2025
2 parents 6b1e5bb + 1192b3f commit 4081366
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2536,12 +2536,27 @@ impl ty::TyExpression {
full_span_for_error = Span::join(full_span_for_error, index_span);
}
(
TypeInfo::Array(elem_ty, _),
ty::ProjectionKind::ArrayIndex { index_span, .. },
TypeInfo::Array(elem_ty, array_length),
ty::ProjectionKind::ArrayIndex { index, index_span },
) => {
parent_rover = symbol;
symbol = elem_ty.type_id;
symbol_span = index_span.clone();

if let Some(index_literal) = index
.expression
.as_literal()
.and_then(|x| x.cast_value_to_u64())
{
if index_literal >= array_length.val() as u64 {
return Err(handler.emit_err(CompileError::ArrayOutOfBounds {
index: index_literal,
count: array_length.val() as u64,
span: index.span.clone(),
}));
}
}

// `index_span` does not contain the enclosing square brackets.
// Which means, if this array index access is the last one before the
// erroneous expression, the `full_span_for_error` will be missing the
Expand Down
9 changes: 0 additions & 9 deletions sway-lib-core/src/primitive_conversions.sw
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ impl u32 {
input: u64
}
}
}

// TODO: This must be in a separate impl block until https://github.com/FuelLabs/sway/issues/1548 is resolved
impl u32 {
/// Extends a `u32` to a `u256`.
///
/// # Returns
Expand Down Expand Up @@ -114,10 +111,7 @@ impl u16 {
input: u64
}
}
}

// TODO: This must be in a separate impl block until https://github.com/FuelLabs/sway/issues/1548 is resolved
impl u16 {
/// Extends a `u16` to a `u256`.
///
/// # Returns
Expand Down Expand Up @@ -204,10 +198,7 @@ impl u8 {
input: u64
}
}
}

// TODO: This must be in a separate impl block until https://github.com/FuelLabs/sway/issues/1548 is resolved
impl u8 {
/// Extends a `u8` to a `u256`.
///
/// # Returns
Expand Down
3 changes: 0 additions & 3 deletions sway-lib-std/src/bytes.sw
Original file line number Diff line number Diff line change
Expand Up @@ -584,10 +584,7 @@ impl Bytes {
pub fn ptr(self) -> raw_ptr {
self.buf.ptr()
}
}

// Need to use separate impl blocks for now: https://github.com/FuelLabs/sway/issues/1548
impl Bytes {
/// Divides one Bytes into two at an index.
///
/// # Additional Information
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[[package]]
name = "array_oob_reassignment"
source = "member"
dependencies = ["core"]

[[package]]
name = "core"
source = "path+from-root-CC73096846C1E083"
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[project]
authors = ["Fuel Labs <[email protected]>"]
license = "Apache-2.0"
name = "array_oob_reassignment"
entry = "main.sw"
implicit-std = false

[dependencies]
core = { path = "../../../../../../sway-lib-core" }
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
script;

fn main() {
let mut a = [u64; 0];
a[0] = 1;


let mut b = [[u64; 1]; 1];
b[0][1] = 1;


b[1][0] = 1;


a[0] = return;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
category = "fail"

# check: $()let mut a = [u64; 0];
# nextln: $()This declaration is never used.

# check: $()let mut b = [[u64; 1]; 1];
# nextln: $()This declaration is never used.

# check: $()a[0] = 1;
# nextln: $()Index out of bounds; the length is 0 but the index is 0.

# check: $()b[0][1] = 1;
# nextln: $()Index out of bounds; the length is 1 but the index is 1.

# check: $()b[1][0] = 1;
# nextln: $()Index out of bounds; the length is 1 but the index is 1.

# check: $()a[0] = return;
# nextln: $()Index out of bounds; the length is 0 but the index is 0.
Original file line number Diff line number Diff line change
Expand Up @@ -779,6 +779,7 @@ fn bytes_append_to_empty() {
};
}

#[test()]
fn bytes_append_self() {
let (mut bytes, a, b, c) = setup();
assert(bytes.len() == 3);
Expand All @@ -797,6 +798,7 @@ fn bytes_append_self() {
assert(bytes.get(5).unwrap() == c);
}

#[test()]
fn bytes_append_empty_self() {
let mut empty_bytes = Bytes::new();

Expand Down

0 comments on commit 4081366

Please sign in to comment.