[ICE] Conditional expression selecting between two public library functions aborts instead of reporting the existing error
- Dominant language
- C++
- Stars
- 25.7k
- Forks
- 6.2k
- Avg merge
- 2d 19h
- Merged PRs (30d)
- 29
Description
## Description
Selecting between two public library functions with a conditional expression and calling the result triggers an internal compiler error, when the conditional is written inside the library that declares them. The operation is not legal — a library cannot call its own public functions externally — and solc reports that correctly when the call is written directly as `C.f()`. Written as a conditional it aborts with an assertion instead. Both branches may name the same function: `(b ? C.f : C.f)()` aborts as well.
Using a `contract` instead of a `library`, declaring the two functions `internal` instead of `public`, evaluating the conditional without calling it, or assigning it to a variable before calling all avoid it. Optimization settings and the choice of backend make no difference.
## Steps to Reproduce
```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library C {
function f() public pure returns (uint256) { return 1; }
function g() public pure returns (uint256) { return 2; }
function test(bool b) public returns (uint256) {
return (b ? C.f : C.g)();
}
}
```
`solc --bin ice.sol` The same error occurs through standard-JSON, and with `--optimize` and `--via-ir`.
```
Internal compiler error:
/solidity/libsolidity/ast/Types.h(1478): Throw in function const Declaration &solidity::frontend::FunctionType::declaration() const
Dynamic exception type: boost::wrapexcept
std::exception::what: Requested declaration from a FunctionType that has none
[solidity::util::tag_comment*] = Requested declaration from a FunctionType that has none
```
## Environment
- Compiler version: 0.8.36+commit.8a079791.Darwin.appleclang
- Target EVM version: osaka (default)
Contributor guide
Assessment
This issue has not been assessed yet.