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(fmt): do not panic when no named arg #9114

Merged
merged 1 commit into from
Oct 14, 2024
Merged
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
7 changes: 5 additions & 2 deletions crates/fmt/src/formatter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2340,8 +2340,11 @@ impl<W: Write> Visitor for Formatter<'_, W> {
""
};
let closing_bracket = format!("{prefix}{}", "}");
let closing_bracket_loc = args.last().unwrap().loc.end();
write_chunk!(self, closing_bracket_loc, "{closing_bracket}")?;
if let Some(arg) = args.last() {
write_chunk!(self, arg.loc.end(), "{closing_bracket}")?;
} else {
write_chunk!(self, "{closing_bracket}")?;
}

Ok(())
}
Expand Down
15 changes: 15 additions & 0 deletions crates/fmt/testdata/Repros/fmt.sol
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,18 @@ contract IfElseTest {
}
}
}

contract DbgFmtTest is Test {
function test_argsList() public {
uint256 result1 = internalNoArgs({});
result2 = add({a: 1, b: 2});
}

function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}

function internalNoArgs() internal pure returns (uint256) {
return 0;
}
}
15 changes: 15 additions & 0 deletions crates/fmt/testdata/Repros/original.sol
Original file line number Diff line number Diff line change
Expand Up @@ -143,3 +143,18 @@ contract IfElseTest {
}
}
}

contract DbgFmtTest is Test {
function test_argsList() public {
uint256 result1 = internalNoArgs({});
result2 = add({a: 1, b: 2});
}

function add(uint256 a, uint256 b) internal pure returns (uint256) {
return a + b;
}

function internalNoArgs() internal pure returns (uint256) {
return 0;
}
}
Loading