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(forge): format new expressions #6408

Merged
merged 7 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from 2 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
4 changes: 4 additions & 0 deletions crates/fmt/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2286,6 +2286,10 @@ impl<'a, W: Write> Visitor for Formatter<'a, W> {
expr.visit(self)?;
stmt.visit(self)?;
}
Expression::New(_, expr) => {
write!(self.buf(), "new ")?;
self.visit_expr(expr.loc(), expr)?;
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here is the fix

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh nice!

_ => self.visit_source(loc)?,
};

Expand Down
2 changes: 1 addition & 1 deletion crates/fmt/testdata/ArrayExpressions/fmt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ contract ArrayExpressions {
uint256[10] memory sample;

uint256 length = 10;
uint256[] memory sample2 = new uint[](length);
uint256[] memory sample2 = new uint256[](length);

uint256[] /* comment1 */ memory /* comment2 */ sample3; // comment3

Expand Down
3 changes: 2 additions & 1 deletion crates/fmt/testdata/ArrayExpressions/original.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ contract ArrayExpressions {
uint[10] memory sample;

uint256 length = 10;
uint[] memory sample2 = new uint[](length);
uint[] memory sample2 = new uint[](
length);

uint /* comment1 */ [] memory /* comment2 */ sample3 // comment3
;
Expand Down
5 changes: 5 additions & 0 deletions crates/fmt/testdata/FunctionCall/bracket-spacing.fmt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,13 @@ contract FunctionCall {

function a(uint256 foo) {
foo;
MyContract c = new MyContract(address(0), hex"beef");
}

function b() {
a({ foo: 5 });
}

contract MyContract {
constructor(address arg, bytes memory data) { }
}
5 changes: 5 additions & 0 deletions crates/fmt/testdata/FunctionCall/fmt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,13 @@ contract FunctionCall {

function a(uint256 foo) {
foo;
MyContract c = new MyContract(address(0), hex"beef");
}

function b() {
a({foo: 5});
}

contract MyContract {
constructor(address arg, bytes memory data) {}
}
5 changes: 5 additions & 0 deletions crates/fmt/testdata/FunctionCall/original.sol
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ contract FunctionCall {

function a(uint256 foo) {
foo;
MyContract c = new MyContract(address( 0),hex"beef");
}

function b() {
a( {foo: 5} );
}

contract MyContract {
constructor(address arg, bytes memory data) {}
}
4 changes: 2 additions & 2 deletions crates/fmt/testdata/FunctionType/fmt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ library ArrayUtils {
pure
returns (uint256[] memory r)
{
r = new uint[](self.length);
r = new uint256[](self.length);
for (uint256 i = 0; i < self.length; i++) {
r[i] = f(self[i]);
}
Expand All @@ -23,7 +23,7 @@ library ArrayUtils {
}

function range(uint256 length) internal pure returns (uint256[] memory r) {
r = new uint[](length);
r = new uint256[](length);
for (uint256 i = 0; i < r.length; i++) {
r[i] = i;
}
Expand Down
4 changes: 2 additions & 2 deletions crates/fmt/testdata/FunctionType/original.sol
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ library ArrayUtils {
uint[] memory r
)
{
r = new uint[](self.length);
r = new uint[]( self.length);
for (uint i = 0; i < self.length; i++) {
r[i] = f(self[i]);
}
Expand All @@ -23,7 +23,7 @@ library ArrayUtils {
}

function range(uint256 length) internal pure returns (uint[] memory r) {
r = new uint[](length);
r = new uint256[](length );
for (uint i = 0; i < r.length; i++) {
r[i] = i;
}
Expand Down
Loading