mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Disallow external function pointers as immutables.
This commit is contained in:
parent
00acaadd10
commit
d68c526eaa
@ -481,8 +481,16 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
else if (_variable.immutable())
|
else if (_variable.immutable())
|
||||||
|
{
|
||||||
if (!_variable.type()->isValueType())
|
if (!_variable.type()->isValueType())
|
||||||
m_errorReporter.typeError(_variable.location(), "Immutable variables cannot have a non-value type.");
|
m_errorReporter.typeError(_variable.location(), "Immutable variables cannot have a non-value type.");
|
||||||
|
if (
|
||||||
|
auto const* functionType = dynamic_cast<FunctionType const*>(_variable.type());
|
||||||
|
functionType && functionType->kind() == FunctionType::Kind::External
|
||||||
|
)
|
||||||
|
m_errorReporter.typeError(_variable.location(), "Immutable variables of external function type are not yet supported.");
|
||||||
|
solAssert(_variable.type()->sizeOnStack() == 1 || m_errorReporter.hasErrors(), "");
|
||||||
|
}
|
||||||
|
|
||||||
if (!_variable.isStateVariable())
|
if (!_variable.isStateVariable())
|
||||||
{
|
{
|
||||||
|
@ -1,12 +0,0 @@
|
|||||||
contract C {
|
|
||||||
function() external returns (uint, uint) immutable public x = this.f;
|
|
||||||
function f() external pure returns (uint, uint) {
|
|
||||||
return (1, 2);
|
|
||||||
}
|
|
||||||
|
|
||||||
function test() external returns (uint, uint) {
|
|
||||||
return this.x()();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ----
|
|
||||||
// test() -> 1, 2
|
|
@ -1,20 +0,0 @@
|
|||||||
contract D {
|
|
||||||
function f() external view returns (uint256) {
|
|
||||||
return 42;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
contract C {
|
|
||||||
D d;
|
|
||||||
function() external view returns(uint256) immutable z;
|
|
||||||
constructor() public {
|
|
||||||
d = new D();
|
|
||||||
z = d.f;
|
|
||||||
}
|
|
||||||
function f() public view returns (uint256) {
|
|
||||||
assert(z.address == address(d));
|
|
||||||
assert(z.selector == D.f.selector);
|
|
||||||
return z();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// ----
|
|
||||||
// f() -> 42
|
|
@ -0,0 +1,5 @@
|
|||||||
|
contract C {
|
||||||
|
function() external immutable f;
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError: (17-48): Immutable variables of external function type are not yet supported.
|
Loading…
Reference in New Issue
Block a user