diff --git a/src/slang-nodes/CatchClauses.ts b/src/slang-nodes/CatchClauses.ts index c13d93b65..5106e0411 100644 --- a/src/slang-nodes/CatchClauses.ts +++ b/src/slang-nodes/CatchClauses.ts @@ -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, print: PrintFunction): Doc { diff --git a/tests/format/TryCatch/TryCatch.sol b/tests/format/TryCatch/TryCatch.sol index 32163da8c..c0b96f5c6 100644 --- a/tests/format/TryCatch/TryCatch.sol +++ b/tests/format/TryCatch/TryCatch.sol @@ -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; + } +} \ No newline at end of file diff --git a/tests/format/TryCatch/__snapshots__/format.test.js.snap b/tests/format/TryCatch/__snapshots__/format.test.js.snap index c288e18e7..6a8b4c80f 100644 --- a/tests/format/TryCatch/__snapshots__/format.test.js.snap +++ b/tests/format/TryCatch/__snapshots__/format.test.js.snap @@ -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; @@ -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; + } +} + ================================================================================ `;