mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Only allow compile-time constants for constant state variables.
This commit is contained in:
parent
533d5d4b1c
commit
8ed3da1d5f
@ -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.
|
||||||
|
@ -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())
|
||||||
{
|
{
|
||||||
|
@ -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.
|
||||||
|
@ -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.
|
||||||
|
Loading…
Reference in New Issue
Block a user