Override semantics for fallback function.

This commit is contained in:
chriseth 2020-11-11 15:24:11 +01:00
parent bb9688e0fe
commit 67ec5f6b17
4 changed files with 38 additions and 9 deletions

View File

@ -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 (

View File

@ -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.

View File

@ -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"?

View File

@ -0,0 +1,7 @@
contract C {
fallback(bytes calldata _input) external virtual returns (bytes memory _output) {}
}
contract D is C {
fallback() external override {}
}
// ----