mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #1018 from ethereum/constructor-constant
Constructor constant
This commit is contained in:
commit
e8cb4d2897
@ -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
|
||||
|
@ -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())
|
||||
|
@ -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()
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user