Skip to content

Commit

Permalink
add require in array slice, remove parsing of emits
Browse files Browse the repository at this point in the history
  • Loading branch information
brockelmore committed Aug 2, 2024
1 parent 81c290c commit 95bd97d
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion crates/pyrometer/tests/test_data/assign.sol
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ contract Assign {
}

function array_slices(
uint[] calldata a
uint[] calldata a,
uint x
) public pure returns (uint[] memory) {
require(a.length >= 4, "Array must have at least 4 elements");
a[2] = 14;
uint[] memory b = a[2:4];
uint[] memory c = a[1:];
uint[] memory d = a[:2];
uint[] memory e = a[2:4][0:1];
uint[] memory f = a[2:x];
}
}
5 changes: 5 additions & 0 deletions crates/solc-expressions/src/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,11 @@ pub trait Array: AnalyzerBackend<Expr = Expression, ExprErr = ExprErr> + Sized {
loc: Loc,
) -> Result<(), ExprErr> {
let arr = ContextVarNode::from(arr.expect_single().into_expr_err(loc)?);

if let (Some(s), Some(e)) = (&start, &end) {
self.handle_require_inner(arena, ctx, e, s, RangeOp::Gte, loc)?;
}

let start = if let Some(start) = start {
Elem::from(ContextVarNode::from(
start.expect_single().into_expr_err(loc)?,
Expand Down
5 changes: 3 additions & 2 deletions crates/solc-expressions/src/context_builder/flattened.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,8 @@ pub trait Flatten:
self.push_expr(FlatExpr::Revert(*loc, named_args.len()));
}
Emit(loc, emit_expr) => {
self.traverse_expression(emit_expr, unchecked);
self.push_expr(FlatExpr::Emit(*loc));
// self.traverse_expression(emit_expr, unchecked);
// self.push_expr(FlatExpr::Emit(*loc));
}
Try(loc, _try_expr, _maybe_returns, _clauses) => {
self.push_expr(FlatExpr::Todo(
Expand Down Expand Up @@ -2075,6 +2075,7 @@ pub trait Flatten:
} else {
None
};

self.slice_inner(arena, ctx, arr, start, end, loc)
}

Expand Down

0 comments on commit 95bd97d

Please sign in to comment.