Properly check getter types to be old-abi-coder-compatible.

This commit is contained in:
chriseth 2018-11-28 12:17:30 +01:00
parent 7cbf046864
commit 46f3da0b87

View File

@ -21,17 +21,24 @@
*/ */
#include <libsolidity/analysis/TypeChecker.h> #include <libsolidity/analysis/TypeChecker.h>
#include <memory> #include <libsolidity/ast/AST.h>
#include <libyul/AsmAnalysis.h>
#include <libyul/AsmAnalysisInfo.h>
#include <libyul/AsmData.h>
#include <liblangutil/ErrorReporter.h>
#include <libdevcore/Algorithms.h>
#include <libdevcore/StringUtils.h>
#include <boost/algorithm/cxx11/all_of.hpp> #include <boost/algorithm/cxx11/all_of.hpp>
#include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/join.hpp> #include <boost/algorithm/string/join.hpp>
#include <boost/range/adaptor/reversed.hpp> #include <boost/range/adaptor/reversed.hpp>
#include <libsolidity/ast/AST.h>
#include <libyul/AsmAnalysis.h> #include <memory>
#include <libyul/AsmAnalysisInfo.h> #include <vector>
#include <libyul/AsmData.h>
#include <liblangutil/ErrorReporter.h>
#include <libdevcore/Algorithms.h>
using namespace std; using namespace std;
using namespace dev; using namespace dev;
@ -814,11 +821,25 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
if (!varType->canLiveOutsideStorage()) if (!varType->canLiveOutsideStorage())
m_errorReporter.typeError(_variable.location(), "Type " + varType->toString() + " is only valid in storage."); m_errorReporter.typeError(_variable.location(), "Type " + varType->toString() + " is only valid in storage.");
} }
else if ( else if (_variable.visibility() >= VariableDeclaration::Visibility::Public)
_variable.visibility() >= VariableDeclaration::Visibility::Public && {
!FunctionType(_variable).interfaceFunctionType() FunctionType getter(_variable);
) if (!_variable.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::ABIEncoderV2))
m_errorReporter.typeError(_variable.location(), "Internal or recursive type is not allowed for public state variables."); {
vector<string> unsupportedTypes;
for (auto const& param: getter.parameterTypes() + getter.returnParameterTypes())
if (!typeSupportedByOldABIEncoder(*param))
unsupportedTypes.emplace_back(param->toString());
if (!unsupportedTypes.empty())
m_errorReporter.typeError(_variable.location(),
"The following types are only supported for getters in the new experimental ABI encoder: " +
joinHumanReadable(unsupportedTypes) +
". Either remove \"public\" or use \"pragma experimental ABIEncoderV2;\" to enable the feature."
);
}
if (!getter.interfaceFunctionType())
m_errorReporter.typeError(_variable.location(), "Internal or recursive type is not allowed for public state variables.");
}
switch (varType->category()) switch (varType->category())
{ {