`try/catch` only catches the very first external call
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 1d 11h
- Merged PRs (30d)
- 21
Description
## Abstract
> **NOTE: This seems to only be breaking if you do another external call from a contract with address(0). e.g. in the example below, if callA returns address(0).**
`try/catch` only catches the very first external call although it allows multiple external calls to be tried. This could be a bit of a footgun if a single external call is not warned or enforced or if each of the external calls in the "try" block are not tried.
## Motivation
This can be slightly confusing when you do something like: `try IContractB(contractA.callA()).callB() {} catch {}`
This will revert if the function `callB` doesn't exist on the address returned by `contractA.callA`.
The interfaces:
```
IContractA {
function callA() external returns (address);
}
IContractB {
function callB() external;
}
```
## Specification
It would make more sense to:
1. not allow multiple external calls to be tried (compiler error)
2. try each of them separately
3. warn that you have multiple external calls in a try "block" (compiler warning)
## Backwards Compatibility
Specifications 2 and 3 would likely be backwards compatible, but Specification 1 would probably break code which violates this rule when they update their solc if this change was made.
Contributor guide
Research direction
The issue provides no source file or test entry point. Start by reproducing the nested external-call example with `try IContractB(contractA.callA()).callB()`, then inspect how `try/catch` handles each external call. Done means selecting and specifying one of the three proposed behaviors and confirming the resulting compiler behavior, including the address(0) case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- solidity
- Domain
- blockchain, compilers
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100