Merge pull request #9319 from ethereum/noCalldataForConstructor

Constructors cannot have calldata parameters.
This commit is contained in:
chriseth 2020-07-06 17:58:23 +02:00 committed by GitHub
commit 9009335b3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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.
* Wasm backend: Properly support both ``i32.drop`` and ``i64.drop``, and remove ``drop``.
* 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.