Constructors cannot have calldata parameters.

This commit is contained in:
chriseth 2020-07-06 16:52:51 +02:00
parent 375cb09341
commit f372ba6fea
4 changed files with 17 additions and 1 deletions

View File

@ -19,6 +19,7 @@ Bugfixes:
* NatSpec: Do not consider ``////`` and ``/***`` as NatSpec comments.
* Type Checker: Fix internal error related to ``using for`` applied to non-libraries.
* Type Checker: Do not disallow assigning to calldata variables.
* Type Checker: Disallow constructor parameters with ``calldata`` data location.
* Wasm backend: Fix code generation for for-loops with pre statements.
* Yul: Fix source location of variable multi-assignment.

View File

@ -588,6 +588,15 @@ bool VariableDeclaration::isInternalCallableParameter() const
return false;
}
bool VariableDeclaration::isConstructorParameter() const
{
if (!isCallableOrCatchParameter())
return false;
if (auto const* function = dynamic_cast<FunctionDefinition const*>(scope()))
return function->isConstructor();
return false;
}
bool VariableDeclaration::isLibraryFunctionParameter() const
{
if (!isCallableOrCatchParameter())
@ -622,7 +631,7 @@ set<VariableDeclaration::Location> VariableDeclaration::allowedDataLocations() c
set<Location> locations{ Location::Memory };
if (isInternalCallableParameter() || isLibraryFunctionParameter() || isTryCatchParameter())
locations.insert(Location::Storage);
if (!isTryCatchParameter())
if (!isTryCatchParameter() && !isConstructorParameter())
locations.insert(Location::CallData);
return locations;

View File

@ -928,6 +928,7 @@ public:
/// @returns true if this variable is a parameter or return parameter of an internal function
/// or a function type of internal visibility.
bool isInternalCallableParameter() const;
bool isConstructorParameter() const;
/// @returns true iff this variable is a parameter(or return parameter of a library function
bool isLibraryFunctionParameter() const;
/// @returns true if the type of the variable does not need to be specified, i.e. it is declared

View File

@ -0,0 +1,5 @@
contract C {
constructor(uint[] calldata) public {}
}
// ----
// TypeError 6651: (29-44): Data location must be "memory" for parameter in function, but "calldata" was given.