From f24097c38d0d27852ced412a2e4704e49a555a8c Mon Sep 17 00:00:00 2001 From: chriseth Date: Mon, 27 Jul 2020 12:33:03 +0200 Subject: [PATCH] Fix internal error for invalid data location in constructor. --- libsolidity/analysis/DeclarationTypeChecker.cpp | 4 +++- .../syntaxTests/constructor/calldata_constructor_args.sol | 2 +- .../syntaxTests/dataLocations/unspecified_constructor.sol | 6 ++++++ 3 files changed, 10 insertions(+), 2 deletions(-) create mode 100644 test/libsolidity/syntaxTests/dataLocations/unspecified_constructor.sol diff --git a/libsolidity/analysis/DeclarationTypeChecker.cpp b/libsolidity/analysis/DeclarationTypeChecker.cpp index d3408e379..15cbc30ba 100644 --- a/libsolidity/analysis/DeclarationTypeChecker.cpp +++ b/libsolidity/analysis/DeclarationTypeChecker.cpp @@ -324,7 +324,9 @@ void DeclarationTypeChecker::endVisit(VariableDeclaration const& _variable) ", ", " or " ); - if (_variable.isCallableOrCatchParameter()) + if (_variable.isConstructorParameter()) + errorString += " for constructor parameter"; + else if (_variable.isCallableOrCatchParameter()) errorString += " for " + string(_variable.isReturnParameter() ? "return " : "") + diff --git a/test/libsolidity/syntaxTests/constructor/calldata_constructor_args.sol b/test/libsolidity/syntaxTests/constructor/calldata_constructor_args.sol index 5562117ce..616fbe5a8 100644 --- a/test/libsolidity/syntaxTests/constructor/calldata_constructor_args.sol +++ b/test/libsolidity/syntaxTests/constructor/calldata_constructor_args.sol @@ -2,4 +2,4 @@ contract C { constructor(uint[] calldata) public {} } // ---- -// TypeError 6651: (29-44): Data location must be "storage" or "memory" for parameter in function, but "calldata" was given. +// TypeError 6651: (29-44): Data location must be "storage" or "memory" for constructor parameter, but "calldata" was given. diff --git a/test/libsolidity/syntaxTests/dataLocations/unspecified_constructor.sol b/test/libsolidity/syntaxTests/dataLocations/unspecified_constructor.sol new file mode 100644 index 000000000..040fe5266 --- /dev/null +++ b/test/libsolidity/syntaxTests/dataLocations/unspecified_constructor.sol @@ -0,0 +1,6 @@ +contract C { + struct S {uint x;} + constructor(S) {} +} +// ---- +// TypeError 6651: (48-49): Data location must be "storage" or "memory" for constructor parameter, but none was given.