Skip to content
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
2 changes: 2 additions & 0 deletions src/slang-nodes/CatchClauses.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ export class CatchClauses extends SlangNode {
super(ast, true);

this.items = ast.items.map((item) => new CatchClause(item, options));

this.updateMetadata(...this.items);
}

print(path: AstPath<CatchClauses>, print: PrintFunction): Doc {
Expand Down
14 changes: 14 additions & 0 deletions tests/format/TryCatch/TryCatch.sol
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,17 @@ contract FeedConsumer {
}
}
}

contract Test {
function getAdjustedBalance(IERC20 token) internal view returns (uint256) {
uint256 balance;

try token.balanceOf(address(this)) returns (uint256 result) {
balance = result;
} catch {
return 0;
}

return balance - 100;
}
}
27 changes: 27 additions & 0 deletions tests/format/TryCatch/__snapshots__/format.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,19 @@ contract FeedConsumer {
}
}

contract Test {
function getAdjustedBalance(IERC20 token) internal view returns (uint256) {
uint256 balance;

try token.balanceOf(address(this)) returns (uint256 result) {
balance = result;
} catch {
return 0;
}

return balance - 100;
}
}
=====================================output=====================================
pragma solidity ^0.6.0;

Expand Down Expand Up @@ -220,5 +233,19 @@ contract FeedConsumer {
}
}

contract Test {
function getAdjustedBalance(IERC20 token) internal view returns (uint256) {
uint256 balance;

try token.balanceOf(address(this)) returns (uint256 result) {
balance = result;
} catch {
return 0;
}

return balance - 100;
}
}

================================================================================
`;