diff options
-rw-r--r-- | Changelog.md | 2 | ||||
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 5 | ||||
-rw-r--r-- | test/libsolidity/SolidityNameAndTypeResolution.cpp | 6 |
3 files changed, 8 insertions, 5 deletions
diff --git a/Changelog.md b/Changelog.md index a80f23f4..ba802834 100644 --- a/Changelog.md +++ b/Changelog.md @@ -17,7 +17,7 @@ Bugfixes: * Type system: Detect cyclic dependencies between constants. * Type system: Disallow arrays with negative length. * Type system: Fix a crash related to invalid binary operators. - * Type system: Only allow compile-time constants for constant state variables. + * Type system: Warn if constant state variables are not compile-time constants. * Type system: Disallow ``var`` declaration with empty tuple type. * Type system: Correctly convert function argument types to pointers for member functions. * Type system: Move privateness of constructor into AST itself. diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 41636db7..8e7ec29b 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -484,9 +484,10 @@ bool TypeChecker::visit(VariableDeclaration const& _variable) if (!_variable.value()) typeError(_variable.location(), "Uninitialized \"constant\" variable."); else if (!_variable.value()->annotation().isPure) - typeError( + warning( _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. " + "This will fail to compile with the next breaking version change." ); } if (!_variable.isStateVariable()) diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp index 71fef32d..27791775 100644 --- a/test/libsolidity/SolidityNameAndTypeResolution.cpp +++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp @@ -2180,7 +2180,8 @@ BOOST_AUTO_TEST_CASE(assigning_state_to_const_variable) address constant x = msg.sender; } )"; - CHECK_ERROR(text, TypeError, "Initial value for constant variable has to be compile-time constant."); + // Change to TypeError for 0.5.0. + CHECK_WARNING(text, "Initial value for constant variable has to be compile-time constant."); } BOOST_AUTO_TEST_CASE(constant_string_literal_disallows_assignment) @@ -2207,7 +2208,8 @@ BOOST_AUTO_TEST_CASE(assign_constant_function_value_to_constant) uint constant y = x(); } )"; - CHECK_ERROR(text, TypeError, "Initial value for constant variable has to be compile-time constant."); + // Change to TypeError for 0.5.0. + CHECK_WARNING(text, "Initial value for constant variable has to be compile-time constant."); } BOOST_AUTO_TEST_CASE(assignment_to_const_var_involving_conversion) |