aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2018-07-04 05:03:26 +0800
committerchriseth <chris@ethereum.org>2018-07-04 05:03:26 +0800
commit8ed3da1d5f744337ba96916d9648a6884a25a3e7 (patch)
treea1252005c3a5d1b950ccf77a8c6e7095fa394a72
parent533d5d4b1cc4374decc704de8c86ad4cef6214fc (diff)
downloaddexon-solidity-8ed3da1d5f744337ba96916d9648a6884a25a3e7.tar
dexon-solidity-8ed3da1d5f744337ba96916d9648a6884a25a3e7.tar.gz
dexon-solidity-8ed3da1d5f744337ba96916d9648a6884a25a3e7.tar.bz2
dexon-solidity-8ed3da1d5f744337ba96916d9648a6884a25a3e7.tar.lz
dexon-solidity-8ed3da1d5f744337ba96916d9648a6884a25a3e7.tar.xz
dexon-solidity-8ed3da1d5f744337ba96916d9648a6884a25a3e7.tar.zst
dexon-solidity-8ed3da1d5f744337ba96916d9648a6884a25a3e7.zip
Only allow compile-time constants for constant state variables.
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/TypeChecker.cpp17
-rw-r--r--test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol2
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/165_assigning_state_to_const_variable.sol2
4 files changed, 7 insertions, 15 deletions
diff --git a/Changelog.md b/Changelog.md
index b36bec2e..eb0ded82 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -28,6 +28,7 @@ Breaking Changes:
* Optimizer: Remove the no-op ``PUSH1 0 NOT AND`` sequence.
* Parser: Disallow trailing dots that are not followed by a number.
* 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 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.
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 3bd0b4c1..676b3cd6 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -749,19 +749,10 @@ bool TypeChecker::visit(VariableDeclaration const& _variable)
if (!_variable.value())
m_errorReporter.typeError(_variable.location(), "Uninitialized \"constant\" variable.");
else if (!_variable.value()->annotation().isPure)
- {
- if (_variable.sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
- m_errorReporter.typeError(
- _variable.value()->location(),
- "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."
- );
- }
+ m_errorReporter.typeError(
+ _variable.value()->location(),
+ "Initial value for constant variable has to be compile-time constant."
+ );
}
if (!_variable.isStateVariable())
{
diff --git a/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol b/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol
index 88e94e29..0e242b30 100644
--- a/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol
+++ b/test/libsolidity/syntaxTests/constants/assign_constant_function_value.sol
@@ -3,4 +3,4 @@ contract C {
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.
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/165_assigning_state_to_const_variable.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/165_assigning_state_to_const_variable.sol
index f3986580..0de15dfb 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/165_assigning_state_to_const_variable.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/165_assigning_state_to_const_variable.sol
@@ -2,4 +2,4 @@ contract C {
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.