mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Bugfix for functions override
- Functions with byte array type parameters can now be safely overriden. Parameter location is now set at the right place. - Also made a test for the fix
This commit is contained in:
parent
a2f5ea88b8
commit
26132363d5
19
AST.cpp
19
AST.cpp
@ -274,15 +274,6 @@ TypePointer FunctionDefinition::getType(ContractDefinition const*) const
|
||||
|
||||
void FunctionDefinition::checkTypeRequirements()
|
||||
{
|
||||
// change all byte arrays parameters to point to calldata
|
||||
if (getVisibility() == Visibility::External)
|
||||
for (ASTPointer<VariableDeclaration> const& var: getParameters())
|
||||
{
|
||||
auto const& type = var->getType();
|
||||
solAssert(!!type, "");
|
||||
if (auto const* byteArrayType = dynamic_cast<ByteArrayType const*>(type.get()))
|
||||
var->setType(byteArrayType->copyForLocation(ByteArrayType::Location::CallData));
|
||||
}
|
||||
for (ASTPointer<VariableDeclaration> const& var: getParameters() + getReturnParameters())
|
||||
if (!var->getType()->canLiveOutsideStorage())
|
||||
BOOST_THROW_EXCEPTION(var->createTypeError("Type is required to live outside storage."));
|
||||
@ -299,16 +290,14 @@ string FunctionDefinition::getCanonicalSignature() const
|
||||
|
||||
bool VariableDeclaration::isLValue() const
|
||||
{
|
||||
if (auto const* function = dynamic_cast<FunctionDefinition const*>(getScope()))
|
||||
if (function->getVisibility() == Declaration::Visibility::External && isFunctionParameter())
|
||||
return false;
|
||||
return true;
|
||||
// External function parameters are Read-Only
|
||||
return !isExternalFunctionParameter();
|
||||
}
|
||||
|
||||
bool VariableDeclaration::isFunctionParameter() const
|
||||
bool VariableDeclaration::isExternalFunctionParameter() const
|
||||
{
|
||||
auto const* function = dynamic_cast<FunctionDefinition const*>(getScope());
|
||||
if (!function)
|
||||
if (!function || function->getVisibility() != Declaration::Visibility::External)
|
||||
return false;
|
||||
for (auto const& variable: function->getParameters())
|
||||
if (variable.get() == this)
|
||||
|
2
AST.h
2
AST.h
@ -448,7 +448,7 @@ public:
|
||||
|
||||
virtual bool isLValue() const override;
|
||||
bool isLocalVariable() const { return !!dynamic_cast<FunctionDefinition const*>(getScope()); }
|
||||
bool isFunctionParameter() const;
|
||||
bool isExternalFunctionParameter() const;
|
||||
bool isStateVariable() const { return m_isStateVariable; }
|
||||
bool isIndexed() const { return m_isIndexed; }
|
||||
|
||||
|
@ -333,7 +333,13 @@ void ReferencesResolver::endVisit(VariableDeclaration& _variable)
|
||||
// or mapping
|
||||
if (_variable.getTypeName())
|
||||
{
|
||||
_variable.setType(_variable.getTypeName()->toType());
|
||||
TypePointer type = _variable.getTypeName()->toType();
|
||||
// All byte array parameter types should point to call data
|
||||
if (_variable.isExternalFunctionParameter())
|
||||
if (auto const* byteArrayType = dynamic_cast<ByteArrayType const*>(type.get()))
|
||||
type = byteArrayType->copyForLocation(ByteArrayType::Location::CallData);
|
||||
_variable.setType(type);
|
||||
|
||||
if (!_variable.getType())
|
||||
BOOST_THROW_EXCEPTION(_variable.getTypeName()->createTypeError("Invalid type name"));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user