Only allow compile-time constants for constant state variables.

This commit is contained in:
chriseth 2018-07-03 23:03:26 +02:00
parent 533d5d4b1c
commit 8ed3da1d5f
4 changed files with 7 additions and 15 deletions

View File

@ -28,6 +28,7 @@ Breaking Changes:
* Optimizer: Remove the no-op ``PUSH1 0 NOT AND`` sequence. * Optimizer: Remove the no-op ``PUSH1 0 NOT AND`` sequence.
* Parser: Disallow trailing dots that are not followed by a number. * Parser: Disallow trailing dots that are not followed by a number.
* Parser: Remove ``constant`` as function state mutability modifer. * Parser: Remove ``constant`` as function state mutability modifer.
* Type Checker: Disallow values for constants that are not compile-time constants. This was already the case in the experimental 0.5.0 mode.
* Type Checker: Disallow arithmetic operations for boolean variables. * Type Checker: Disallow arithmetic operations for boolean variables.
* Type Checker: Disallow conversions between ``bytesX`` and ``uintY`` of different size. * Type Checker: Disallow conversions between ``bytesX`` and ``uintY`` of different size.
* Type Checker: Disallow specifying base constructor arguments multiple times in the same inheritance hierarchy. This was already the case in the experimental 0.5.0 mode. * Type Checker: Disallow specifying base constructor arguments multiple times in the same inheritance hierarchy. This was already the case in the experimental 0.5.0 mode.

View File

@ -749,19 +749,10 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
if (!_variable.value()) if (!_variable.value())
m_errorReporter.typeError(_variable.location(), "Uninitialized \"constant\" variable."); m_errorReporter.typeError(_variable.location(), "Uninitialized \"constant\" variable.");
else if (!_variable.value()->annotation().isPure) else if (!_variable.value()->annotation().isPure)
{
if (_variable.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
m_errorReporter.typeError( m_errorReporter.typeError(
_variable.value()->location(), _variable.value()->location(),
"Initial value for constant variable has to be compile-time constant." "Initial value for constant variable has to be compile-time constant."
); );
else
m_errorReporter.warning(
_variable.value()->location(),
"Initial value for constant variable has to be compile-time constant. "
"This will fail to compile with the next breaking version change."
);
}
} }
if (!_variable.isStateVariable()) if (!_variable.isStateVariable())
{ {

View File

@ -3,4 +3,4 @@ contract C {
uint constant y = x(); uint constant y = x();
} }
// ---- // ----
// Warning: (74-77): Initial value for constant variable has to be compile-time constant. This will fail to compile with the next breaking version change. // TypeError: (74-77): Initial value for constant variable has to be compile-time constant.

View File

@ -2,4 +2,4 @@ contract C {
address constant x = msg.sender; address constant x = msg.sender;
} }
// ---- // ----
// Warning: (38-48): Initial value for constant variable has to be compile-time constant. This will fail to compile with the next breaking version change. // TypeError: (38-48): Initial value for constant variable has to be compile-time constant.