mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #8859 from ethereum/noRuntimeForImmutable
trigger error when runtimeCode is called on contracts with immutables
This commit is contained in:
commit
3212cb6caa
@ -10,7 +10,7 @@ Compiler Features:
|
|||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
* ABI: Skip ``private`` or ``internal`` constructors.
|
* ABI: Skip ``private`` or ``internal`` constructors.
|
||||||
|
* Type Checker: Disallow accessing ``runtimeCode`` for contract types that contain immutable state variables.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2663,9 +2663,19 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
|
|||||||
))
|
))
|
||||||
{
|
{
|
||||||
annotation.isPure = true;
|
annotation.isPure = true;
|
||||||
m_scope->annotation().contractDependencies.insert(
|
ContractType const& accessedContractType = dynamic_cast<ContractType const&>(*magicType->typeArgument());
|
||||||
&dynamic_cast<ContractType const&>(*magicType->typeArgument()).contractDefinition()
|
m_scope->annotation().contractDependencies.insert(&accessedContractType.contractDefinition());
|
||||||
);
|
|
||||||
|
if (
|
||||||
|
memberName == "runtimeCode" &&
|
||||||
|
!accessedContractType.immutableVariables().empty()
|
||||||
|
)
|
||||||
|
m_errorReporter.typeError(
|
||||||
|
9274_error,
|
||||||
|
_memberAccess.location(),
|
||||||
|
"\"runtimeCode\" is not available for contracts containing immutable variables."
|
||||||
|
);
|
||||||
|
|
||||||
if (contractDependenciesAreCyclic(*m_scope))
|
if (contractDependenciesAreCyclic(*m_scope))
|
||||||
m_errorReporter.typeError(
|
m_errorReporter.typeError(
|
||||||
4224_error,
|
4224_error,
|
||||||
|
9
test/libsolidity/syntaxTests/immutable/creationCode.sol
Normal file
9
test/libsolidity/syntaxTests/immutable/creationCode.sol
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
contract A {
|
||||||
|
address public immutable user = address(0x0);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Test {
|
||||||
|
function test() public pure returns(bytes memory) {
|
||||||
|
return type(A).creationCode;
|
||||||
|
}
|
||||||
|
}
|
11
test/libsolidity/syntaxTests/immutable/runtimeCode.sol
Normal file
11
test/libsolidity/syntaxTests/immutable/runtimeCode.sol
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
contract A {
|
||||||
|
address public immutable user = address(0x0);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Test {
|
||||||
|
function test() public pure returns(bytes memory) {
|
||||||
|
return type(A).runtimeCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (153-172): "runtimeCode" is not available for contracts containing immutable variables.
|
@ -0,0 +1,13 @@
|
|||||||
|
contract Base {
|
||||||
|
address public immutable user = address(0x0);
|
||||||
|
}
|
||||||
|
|
||||||
|
contract Derived is Base {}
|
||||||
|
|
||||||
|
contract Test {
|
||||||
|
function test() public pure returns(bytes memory) {
|
||||||
|
return type(Derived).runtimeCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (185-210): "runtimeCode" is not available for contracts containing immutable variables.
|
Loading…
Reference in New Issue
Block a user