diff --git a/crates/fmt/src/formatter.rs b/crates/fmt/src/formatter.rs index 02b7bd7fe9a5f..02d62f70567a8 100644 --- a/crates/fmt/src/formatter.rs +++ b/crates/fmt/src/formatter.rs @@ -2340,8 +2340,11 @@ impl 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(()) } diff --git a/crates/fmt/testdata/Repros/fmt.sol b/crates/fmt/testdata/Repros/fmt.sol index a61a626a0968f..0a480c0b02bdf 100644 --- a/crates/fmt/testdata/Repros/fmt.sol +++ b/crates/fmt/testdata/Repros/fmt.sol @@ -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; + } +} diff --git a/crates/fmt/testdata/Repros/original.sol b/crates/fmt/testdata/Repros/original.sol index ef75931e233e6..6f18784d39dea 100644 --- a/crates/fmt/testdata/Repros/original.sol +++ b/crates/fmt/testdata/Repros/original.sol @@ -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; + } +}