Skip to content

Commit 0c50634

Browse files
authored
updating metadata of CatchClauses array (#1295)
1 parent 0bbea0a commit 0c50634

File tree

3 files changed

+43
-0
lines changed

3 files changed

+43
-0
lines changed

src/slang-nodes/CatchClauses.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ export class CatchClauses extends SlangNode {
1919
super(ast, true);
2020

2121
this.items = ast.items.map((item) => new CatchClause(item, options));
22+
23+
this.updateMetadata(...this.items);
2224
}
2325

2426
print(path: AstPath<CatchClauses>, print: PrintFunction): Doc {

tests/format/TryCatch/TryCatch.sol

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,3 +101,17 @@ contract FeedConsumer {
101101
}
102102
}
103103
}
104+
105+
contract Test {
106+
function getAdjustedBalance(IERC20 token) internal view returns (uint256) {
107+
uint256 balance;
108+
109+
try token.balanceOf(address(this)) returns (uint256 result) {
110+
balance = result;
111+
} catch {
112+
return 0;
113+
}
114+
115+
return balance - 100;
116+
}
117+
}

tests/format/TryCatch/__snapshots__/format.test.js.snap

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,19 @@ contract FeedConsumer {
110110
}
111111
}
112112
113+
contract Test {
114+
function getAdjustedBalance(IERC20 token) internal view returns (uint256) {
115+
uint256 balance;
116+
117+
try token.balanceOf(address(this)) returns (uint256 result) {
118+
balance = result;
119+
} catch {
120+
return 0;
121+
}
122+
123+
return balance - 100;
124+
}
125+
}
113126
=====================================output=====================================
114127
pragma solidity ^0.6.0;
115128
@@ -220,5 +233,19 @@ contract FeedConsumer {
220233
}
221234
}
222235
236+
contract Test {
237+
function getAdjustedBalance(IERC20 token) internal view returns (uint256) {
238+
uint256 balance;
239+
240+
try token.balanceOf(address(this)) returns (uint256 result) {
241+
balance = result;
242+
} catch {
243+
return 0;
244+
}
245+
246+
return balance - 100;
247+
}
248+
}
249+
223250
================================================================================
224251
`;

0 commit comments

Comments
 (0)