solidity
solidity copied to clipboard
Using constant from library gives error
Description
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
library MyLib {
uint internal constant val1 = 3;
uint internal constant useVal1InMyLib = val1 / 2;
}
contract MyContract {
uint constant useVal1InMyContract = MyLib.val1 / 2; // this line errors
}
Error:
TypeError: Initial value for constant variable has to be compile-time constant.
--> contracts/Const.sol:12:41:
|
12 | uint constant useVal1InMyContract = MyLib.val1 / 2;
| ^^^^^^^^^^^^^^
Since the val1 is marked as constant, it is seen as compile time constant in MyLib, but it should be compile time constant in MyContract too.
Environment
- Compiler version: 0.8.15
- Target EVM version (as per compiler settings): berlin
- Framework/IDE (e.g. Truffle or Remix): Remix
- EVM execution environment / backend / blockchain client: hardhat
- Operating system: macos