aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity/analysis
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-11-29 00:05:52 +0800
committerGitHub <noreply@github.com>2018-11-29 00:05:52 +0800
commitb4086ac87037813eb553e92839bbc40de6bbd9ac (patch)
tree0e88832b720616b9e3525b443dc5f955d772bdbe /libsolidity/analysis
parent463951e8cdd9d3d36b4d1b1e1dd41bb8f54bb73c (diff)
parent9ba3532eac1ad2a647a327c19509b409a2cfb6f2 (diff)
downloaddexon-solidity-b4086ac87037813eb553e92839bbc40de6bbd9ac.tar.gz
dexon-solidity-b4086ac87037813eb553e92839bbc40de6bbd9ac.tar.zst
dexon-solidity-b4086ac87037813eb553e92839bbc40de6bbd9ac.zip
Merge pull request #5526 from ethereum/fixGetterNewCoder
Fix: Disallow structs in getters for old encoder.
Diffstat (limited to 'libsolidity/analysis')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp41
1 files changed, 31 insertions, 10 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index c41c372b..e1a89dd4 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -21,17 +21,24 @@
*/
#include <libsolidity/analysis/TypeChecker.h>
-#include <memory>
-#include <boost/algorithm/cxx11/all_of.hpp>
-#include <boost/algorithm/string/predicate.hpp>
-#include <boost/algorithm/string/join.hpp>
-#include <boost/range/adaptor/reversed.hpp>
#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/string/predicate.hpp>
+#include <boost/algorithm/string/join.hpp>
+#include <boost/range/adaptor/reversed.hpp>
+
+#include <memory>
+#include <vector>
using namespace std;
using namespace dev;
@@ -809,11 +816,25 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
if (!varType->canLiveOutsideStorage())
m_errorReporter.typeError(_variable.location(), "Type " + varType->toString() + " is only valid in storage.");
}
- else if (
- _variable.visibility() >= VariableDeclaration::Visibility::Public &&
- !FunctionType(_variable).interfaceFunctionType()
- )
- m_errorReporter.typeError(_variable.location(), "Internal or recursive type is not allowed for public state variables.");
+ else if (_variable.visibility() >= VariableDeclaration::Visibility::Public)
+ {
+ FunctionType getter(_variable);
+ if (!_variable.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::ABIEncoderV2))
+ {
+ 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())
{