diff options
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 39 | ||||
-rw-r--r-- | libsolidity/ast/AST.h | 2 | ||||
-rw-r--r-- | libsolidity/ast/ASTJsonConverter.cpp | 6 | ||||
-rw-r--r-- | libsolidity/ast/ASTPrinter.cpp | 2 | ||||
-rw-r--r-- | libsolidity/ast/Types.cpp | 14 |
5 files changed, 33 insertions, 30 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index ca848dd0..0764bf67 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -84,8 +84,13 @@ bool TypeChecker::visit(ContractDefinition const& _contract) { if (!function->returnParameters().empty()) m_errorReporter.typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor."); - if (function->isDeclaredConst()) - m_errorReporter.typeError(function->location(), "Constructor cannot be defined as constant."); + if (function->stateMutability() != StateMutability::NonPayable && function->stateMutability() != StateMutability::Payable) + m_errorReporter.typeError( + function->location(), + "Constructor must be payable or non-payable, but is \"" + + stateMutabilityToString(function->stateMutability()) + + "\"." + ); if (function->visibility() != FunctionDefinition::Visibility::Public && function->visibility() != FunctionDefinition::Visibility::Internal) m_errorReporter.typeError(function->location(), "Constructor must be public or internal."); } @@ -104,8 +109,13 @@ bool TypeChecker::visit(ContractDefinition const& _contract) fallbackFunction = function; if (_contract.isLibrary()) m_errorReporter.typeError(fallbackFunction->location(), "Libraries cannot have fallback functions."); - if (fallbackFunction->isDeclaredConst()) - m_errorReporter.typeError(fallbackFunction->location(), "Fallback function cannot be declared constant."); + if (function->stateMutability() != StateMutability::NonPayable && function->stateMutability() != StateMutability::Payable) + m_errorReporter.typeError( + function->location(), + "Fallback function must be payable or non-payable, but is \"" + + stateMutabilityToString(function->stateMutability()) + + "\"." + ); if (!fallbackFunction->parameters().empty()) m_errorReporter.typeError(fallbackFunction->parameterList().location(), "Fallback function cannot take parameters."); if (!fallbackFunction->returnParameters().empty()) @@ -308,17 +318,16 @@ void TypeChecker::checkFunctionOverride(FunctionDefinition const& function, Func if (function.visibility() != super.visibility()) overrideError(function, super, "Overriding function visibility differs."); - else if (function.isDeclaredConst() && !super.isDeclaredConst()) - overrideError(function, super, "Overriding function should not be declared constant."); - - else if (!function.isDeclaredConst() && super.isDeclaredConst()) - overrideError(function, super, "Overriding function should be declared constant."); - - else if (function.isPayable() && !super.isPayable()) - overrideError(function, super, "Overriding function should not be declared payable."); - - else if (!function.isPayable() && super.isPayable()) - overrideError(function, super, "Overriding function should be declared payable."); + else if (function.stateMutability() != super.stateMutability()) + overrideError( + function, + super, + "Overriding function changes state mutability from \"" + + stateMutabilityToString(super.stateMutability()) + + "\" to \"" + + stateMutabilityToString(function.stateMutability()) + + "\"." + ); else if (functionType != superType) overrideError(function, super, "Overriding function return types differ."); diff --git a/libsolidity/ast/AST.h b/libsolidity/ast/AST.h index 8a577c0c..53a34d32 100644 --- a/libsolidity/ast/AST.h +++ b/libsolidity/ast/AST.h @@ -608,7 +608,6 @@ public: StateMutability stateMutability() const { return m_stateMutability; } bool isConstructor() const { return m_isConstructor; } bool isFallback() const { return name().empty(); } - bool isDeclaredConst() const { return m_stateMutability == StateMutability::View; } bool isPayable() const { return m_stateMutability == StateMutability::Payable; } std::vector<ASTPointer<ModifierInvocation>> const& modifiers() const { return m_functionModifiers; } std::vector<ASTPointer<VariableDeclaration>> const& returnParameters() const { return m_returnParameters->parameters(); } @@ -913,7 +912,6 @@ public: return m_visibility == Declaration::Visibility::Default ? Declaration::Visibility::Internal : m_visibility; } StateMutability stateMutability() const { return m_stateMutability; } - bool isDeclaredConst() const { return m_stateMutability == StateMutability::View; } bool isPayable() const { return m_stateMutability == StateMutability::Payable; } private: diff --git a/libsolidity/ast/ASTJsonConverter.cpp b/libsolidity/ast/ASTJsonConverter.cpp index abee55ee..3f16db23 100644 --- a/libsolidity/ast/ASTJsonConverter.cpp +++ b/libsolidity/ast/ASTJsonConverter.cpp @@ -323,8 +323,9 @@ bool ASTJsonConverter::visit(FunctionDefinition const& _node) { std::vector<pair<string, Json::Value>> attributes = { make_pair("name", _node.name()), - make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.isDeclaredConst()), + make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.stateMutability() == StateMutability::View), make_pair("payable", _node.isPayable()), + make_pair("statemutability", stateMutabilityToString(_node.stateMutability())), make_pair("visibility", Declaration::visibilityToString(_node.visibility())), make_pair("parameters", toJson(_node.parameterList())), make_pair("isConstructor", _node.isConstructor()), @@ -419,7 +420,8 @@ bool ASTJsonConverter::visit(FunctionTypeName const& _node) setJsonNode(_node, "FunctionTypeName", { make_pair("payable", _node.isPayable()), make_pair("visibility", Declaration::visibilityToString(_node.visibility())), - make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.isDeclaredConst()), + make_pair("statemutability", stateMutabilityToString(_node.stateMutability())), + make_pair(m_legacy ? "constant" : "isDeclaredConst", _node.stateMutability() == StateMutability::View), make_pair("parameterTypes", toJson(*_node.parameterTypeList())), make_pair("returnParameterTypes", toJson(*_node.returnParameterTypeList())), make_pair("typeDescriptions", typePointerToJson(_node.annotation().type)) diff --git a/libsolidity/ast/ASTPrinter.cpp b/libsolidity/ast/ASTPrinter.cpp index 23eb3b64..bcb5e3b9 100644 --- a/libsolidity/ast/ASTPrinter.cpp +++ b/libsolidity/ast/ASTPrinter.cpp @@ -105,7 +105,7 @@ bool ASTPrinter::visit(FunctionDefinition const& _node) { writeLine("FunctionDefinition \"" + _node.name() + "\"" + (_node.isPublic() ? " - public" : "") + - (_node.isDeclaredConst() ? " - const" : "")); + (_node.stateMutability() == StateMutability::View ? " - const" : "")); printSourcePart(_node); return goDeeper(); } diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index 302f1022..e6664895 100644 --- a/libsolidity/ast/Types.cpp +++ b/libsolidity/ast/Types.cpp @@ -2215,10 +2215,7 @@ string FunctionType::identifier() const case Kind::Require: id += "require";break; default: solAssert(false, "Unknown function location."); break; } - if (isConstant()) - id += "_constant"; - if (isPayable()) - id += "_payable"; + id += "_" + stateMutabilityToString(m_stateMutability); id += identifierList(m_parameterTypes) + "returns" + identifierList(m_returnParameterTypes); if (m_gasSet) id += "gas"; @@ -2237,8 +2234,7 @@ bool FunctionType::operator==(Type const& _other) const FunctionType const& other = dynamic_cast<FunctionType const&>(_other); if ( m_kind != other.m_kind || - isConstant() != other.isConstant() || - isPayable() != other.isPayable() || + m_stateMutability != other.stateMutability() || m_parameterTypes.size() != other.m_parameterTypes.size() || m_returnParameterTypes.size() != other.m_returnParameterTypes.size() ) @@ -2300,10 +2296,8 @@ string FunctionType::toString(bool _short) const for (auto it = m_parameterTypes.begin(); it != m_parameterTypes.end(); ++it) name += (*it)->toString(_short) + (it + 1 == m_parameterTypes.end() ? "" : ","); name += ")"; - if (isConstant()) - name += " constant"; - if (isPayable()) - name += " payable"; + if (m_stateMutability != StateMutability::NonPayable) + name += " " + stateMutabilityToString(m_stateMutability); if (m_kind == Kind::External) name += " external"; if (!m_returnParameterTypes.empty()) |