We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
https://www.wtf.academy/docs/solidity-101/Constant/ wtf solidity 101 的 常量那里描述的 immutable 初始化之后 ,构造函数里重新赋值会报编译错的问题,可能有点错误。 本地测试: // SPDX-License-Identifier: MIT pragma solidity ^0.8.21; contract SolidityConstant { // 利用constructor初始化immutable变量,因此可以利用 // immutable变量可以在constructor里初始化,之后不能改变 uint256 public immutable IMMUTABLE_NUM = 9999999999; constructor() { // Right use case IMMUTABLE_NUM = 123; // 这里编译通过 Remix 并没有提示编译错误 } }
The text was updated successfully, but these errors were encountered:
在Solidity v8.0.21以后,immutable变量不需要显式初始化。反之,则需要显式初始化。 若immutable变量既在声明时初始化,又在constructor中初始化,会使用constructor初始化的值。
Sorry, something went wrong.
请提供更详细的信息 @banxiu
No branches or pull requests
Details(细节)
https://www.wtf.academy/docs/solidity-101/Constant/
wtf solidity 101 的 常量那里描述的 immutable 初始化之后 ,构造函数里重新赋值会报编译错的问题,可能有点错误。
本地测试:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.21;
contract SolidityConstant {
// 利用constructor初始化immutable变量,因此可以利用
// immutable变量可以在constructor里初始化,之后不能改变
uint256 public immutable IMMUTABLE_NUM = 9999999999;
constructor() {
// Right use case
IMMUTABLE_NUM = 123; // 这里编译通过 Remix 并没有提示编译错误
}
}
Are you willing to submit a PR?(你愿意提交PR吗?)
The text was updated successfully, but these errors were encountered: