argotorg / argotorg/solidity

[ICE] Conditional expression selecting between two library functions with different state mutability aborts when called

Open
#16,906 1 comment 0 reactions 1 assignee Claimed by @matheusaaguiar View on GitHub
bug :bug:
Dominant language
C++
Stars
25.7k
Forks
6.2k
Avg merge
1d 11h
Merged PRs (30d)
21

Description

## Description

A conditional expression selecting between two public library functions triggers an internal compiler error when the result is called, if the two functions differ in state mutability. Here `H.f` has type `function () external returns (uint256)` while `H.g` has `function () external pure returns (uint256)`, so the call requires the implicit non-payable to `pure` function conversion. That conversion is legal, and every other construct that performs it compiles: an inline array literal `[H.f, H.g]`, a tuple assignment, assignment through a variable.

Making both functions `pure`, or both non-payable, makes the contract compile; every mismatched pair aborts, whether or not the two functions belong to the same library. Calling `H.f()` directly, using a `contract` instead of a `library`, and `internal` library functions also avoid it. Optimization settings make no difference, and via-IR aborts as well, in `YulUtilFunctions::conversionFunction` rather than `CompilerUtils::convertType`.

## Steps to Reproduce

```solidity
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

library H {
function f() public returns (uint256) { }
function g() public pure returns (uint256) { }
}

contract C {
function t(bool b) public returns (uint256) {
return (b ? H.f : H.g)();
}
}
```

`solc --bin ice.sol` The same error occurs through standard-JSON and with `--optimize`; `--via-ir` also aborts, in `YulUtilFunctions::conversionFunction`.

```
Internal compiler error:
/solidity/libsolidity/codegen/CompilerUtils.cpp(1316): Throw in function void solidity::frontend::CompilerUtils::convertType(const Type &, const Type &, bool, bool, bool)
Dynamic exception type: boost::wrapexcept
std::exception::what: Invalid function type conversion requested.
[solidity::util::tag_comment*] = Invalid function type conversion requested.
```

## Environment

- Compiler version: 0.8.36+commit.8a079791.Darwin.appleclang
- Target EVM version: osaka (default)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.