aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/ReferencesResolver.cpp
diff options
context:
space:
mode:
authorchriseth <c@ethdev.com>2015-10-02 19:11:38 +0800
committerchriseth <c@ethdev.com>2015-10-06 20:19:56 +0800
commit9cc7402c9583ca3bfc9fcb234443d2f90b890190 (patch)
treeb69181225de53fefc5df93dd64e6885db9d85eb0 /libsolidity/ReferencesResolver.cpp
parentd2332769d3e87b3500638591c23241ebd942fbb1 (diff)
downloaddexon-solidity-9cc7402c9583ca3bfc9fcb234443d2f90b890190.tar
dexon-solidity-9cc7402c9583ca3bfc9fcb234443d2f90b890190.tar.gz
dexon-solidity-9cc7402c9583ca3bfc9fcb234443d2f90b890190.tar.bz2
dexon-solidity-9cc7402c9583ca3bfc9fcb234443d2f90b890190.tar.lz
dexon-solidity-9cc7402c9583ca3bfc9fcb234443d2f90b890190.tar.xz
dexon-solidity-9cc7402c9583ca3bfc9fcb234443d2f90b890190.tar.zst
dexon-solidity-9cc7402c9583ca3bfc9fcb234443d2f90b890190.zip
Split external type into ecoding and interface type.
Diffstat (limited to 'libsolidity/ReferencesResolver.cpp')
-rw-r--r--libsolidity/ReferencesResolver.cpp54
1 files changed, 36 insertions, 18 deletions
diff --git a/libsolidity/ReferencesResolver.cpp b/libsolidity/ReferencesResolver.cpp
index 623ac8f7..cb34c47e 100644
--- a/libsolidity/ReferencesResolver.cpp
+++ b/libsolidity/ReferencesResolver.cpp
@@ -106,27 +106,45 @@ void ReferencesResolver::endVisit(VariableDeclaration const& _variable)
// References are forced to calldata for external function parameters (not return)
// and memory for parameters (also return) of publicly visible functions.
// They default to memory for function parameters and storage for local variables.
+ // As an exception, "storage" is allowed for library functions.
if (auto ref = dynamic_cast<ReferenceType const*>(type.get()))
{
- if (_variable.isExternalCallableParameter())
+ if (_variable.isCallableParameter())
{
- // force location of external function parameters (not return) to calldata
- if (loc != Location::Default)
- BOOST_THROW_EXCEPTION(_variable.createTypeError(
- "Location has to be calldata for external functions "
- "(remove the \"memory\" or \"storage\" keyword)."
- ));
- type = ref->copyForLocation(DataLocation::CallData, true);
- }
- else if (_variable.isCallableParameter() && _variable.scope()->isPublic())
- {
- // force locations of public or external function (return) parameters to memory
- if (loc == VariableDeclaration::Location::Storage)
- BOOST_THROW_EXCEPTION(_variable.createTypeError(
- "Location has to be memory for publicly visible functions "
- "(remove the \"storage\" keyword)."
- ));
- type = ref->copyForLocation(DataLocation::Memory, true);
+ auto const& contract = dynamic_cast<ContractDefinition const&>(*_variable.scope()->scope());
+ if (_variable.isExternalCallableParameter())
+ {
+ if (contract.isLibrary())
+ {
+ if (loc == Location::Memory)
+ BOOST_THROW_EXCEPTION(_variable.createTypeError(
+ "Location has to be calldata or storage for external "
+ "library functions (remove the \"memory\" keyword)."
+ ));
+ }
+ else
+ {
+ // force location of external function parameters (not return) to calldata
+ if (loc != Location::Default)
+ BOOST_THROW_EXCEPTION(_variable.createTypeError(
+ "Location has to be calldata for external functions "
+ "(remove the \"memory\" or \"storage\" keyword)."
+ ));
+ }
+ if (loc == Location::Default)
+ type = ref->copyForLocation(DataLocation::CallData, true);
+ }
+ else if (_variable.isCallableParameter() && _variable.scope()->isPublic())
+ {
+ // force locations of public or external function (return) parameters to memory
+ if (loc == Location::Storage && !contract.isLibrary())
+ BOOST_THROW_EXCEPTION(_variable.createTypeError(
+ "Location has to be memory for publicly visible functions "
+ "(remove the \"storage\" keyword)."
+ ));
+ if (loc == Location::Default)
+ type = ref->copyForLocation(DataLocation::Memory, true);
+ }
}
else
{