mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Override semantics for fallback function.
This commit is contained in:
parent
bb9688e0fe
commit
67ec5f6b17
@ -394,6 +394,10 @@ bool OverrideProxy::OverrideComparator::operator<(OverrideComparator const& _oth
|
|||||||
if (functionKind != _other.functionKind)
|
if (functionKind != _other.functionKind)
|
||||||
return *functionKind < *_other.functionKind;
|
return *functionKind < *_other.functionKind;
|
||||||
|
|
||||||
|
// Parameters do not matter for non-regular functions.
|
||||||
|
if (functionKind != Token::Function)
|
||||||
|
return false;
|
||||||
|
|
||||||
if (!parameterTypes || !_other.parameterTypes)
|
if (!parameterTypes || !_other.parameterTypes)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@ -574,6 +578,8 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
|
|||||||
FunctionType const* functionType = _overriding.functionType();
|
FunctionType const* functionType = _overriding.functionType();
|
||||||
FunctionType const* superType = _super.functionType();
|
FunctionType const* superType = _super.functionType();
|
||||||
|
|
||||||
|
if (_overriding.functionKind() != Token::Fallback)
|
||||||
|
{
|
||||||
solAssert(functionType->hasEqualParameterTypes(*superType), "Override doesn't have equal parameters!");
|
solAssert(functionType->hasEqualParameterTypes(*superType), "Override doesn't have equal parameters!");
|
||||||
|
|
||||||
if (!functionType->hasEqualReturnTypes(*superType))
|
if (!functionType->hasEqualReturnTypes(*superType))
|
||||||
@ -584,6 +590,7 @@ void OverrideChecker::checkOverride(OverrideProxy const& _overriding, OverridePr
|
|||||||
"Overriding " + _overriding.astNodeName() + " return types differ.",
|
"Overriding " + _overriding.astNodeName() + " return types differ.",
|
||||||
"Overridden " + _overriding.astNodeName() + " is here:"
|
"Overridden " + _overriding.astNodeName() + " is here:"
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
// Stricter mutability is always okay except when super is Payable
|
// Stricter mutability is always okay except when super is Payable
|
||||||
if (
|
if (
|
||||||
|
@ -0,0 +1,6 @@
|
|||||||
|
contract C {
|
||||||
|
fallback(bytes calldata _input) external returns (bytes memory _output) {}
|
||||||
|
fallback() external {}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// DeclarationError 7301: (96-118): Only one fallback function is allowed.
|
@ -0,0 +1,9 @@
|
|||||||
|
contract C {
|
||||||
|
fallback(bytes calldata _input) external returns (bytes memory _output) {}
|
||||||
|
}
|
||||||
|
contract D is C {
|
||||||
|
fallback() external {}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// TypeError 9456: (116-138): Overriding function is missing "override" specifier.
|
||||||
|
// TypeError 4334: (17-91): Trying to override non-virtual function. Did you forget to add "virtual"?
|
@ -0,0 +1,7 @@
|
|||||||
|
contract C {
|
||||||
|
fallback(bytes calldata _input) external virtual returns (bytes memory _output) {}
|
||||||
|
}
|
||||||
|
contract D is C {
|
||||||
|
fallback() external override {}
|
||||||
|
}
|
||||||
|
// ----
|
Loading…
Reference in New Issue
Block a user