From 319ec340934480eeb044c8c4e35e0471998bd733 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 6 Sep 2016 02:50:47 +0100 Subject: Reject constant constructors --- libsolidity/analysis/TypeChecker.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index fc1b1f59..41a5d39e 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -75,8 +75,12 @@ bool TypeChecker::visit(ContractDefinition const& _contract) checkContractAbstractConstructors(_contract); FunctionDefinition const* function = _contract.constructor(); - if (function && !function->returnParameters().empty()) - typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor."); + if (function) { + if (!function->returnParameters().empty()) + typeError(function->returnParameterList()->location(), "Non-empty \"returns\" directive for constructor."); + if (function->isDeclaredConst()) + typeError(function->location(), "Constructor cannot be defined as constant."); + } FunctionDefinition const* fallbackFunction = nullptr; for (FunctionDefinition const* function: _contract.definedFunctions()) -- cgit From 05ae5e4f5a3246c3af32b9ca1f8244acd7382ee8 Mon Sep 17 00:00:00 2001 From: Alex Beregszaszi Date: Tue, 6 Sep 2016 02:51:01 +0100 Subject: Tests for constant constructors --- test/libsolidity/SolidityNameAndTypeResolution.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 882557fd..4de2c126 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -3989,6 +3989,17 @@ BOOST_AUTO_TEST_CASE(unsatisfied_version) BOOST_CHECK(expectError(text, true) == Error::Type::SyntaxError); } +BOOST_AUTO_TEST_CASE(constant_constructor) +{ + char const* text = R"( + contract test { + function test() constant {} + } + )"; + BOOST_CHECK(expectError(text, false) == Error::Type::TypeError); +} + + BOOST_AUTO_TEST_SUITE_END() } -- cgit From 347b6b484398ccbb82fbc5cab0cada54bb07548a Mon Sep 17 00:00:00 2001 From: chriseth Date: Tue, 6 Sep 2016 15:44:46 +0200 Subject: Update Changelog.md --- Changelog.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Changelog.md b/Changelog.md index 2d9c6c31..4d880a20 100644 --- a/Changelog.md +++ b/Changelog.md @@ -22,6 +22,7 @@ Breaking Changes: * Modifiers: return does not skip part in modifier after ``_`` * Placeholder statement `_` in modifier now requires explicit `;`. * ``ecrecover`` now returns zero if the input is malformed (it previously returned garbage) + * The ``constant`` keyword cannot be used for constructors or the fallback function. * Removed ``--interface`` (Solidity interface) output option * JSON AST: General cleanup, renamed many nodes to match their C++ names. * Json Output: srcmap-runtime renamed to srcmapRuntime -- cgit