diff options
author | chriseth <c@ethdev.com> | 2017-03-15 02:25:16 +0800 |
---|---|---|
committer | chriseth <c@ethdev.com> | 2017-03-15 02:25:16 +0800 |
commit | 9f328ff749477106a569e679e5eeed5c7e78d29d (patch) | |
tree | 4ed950ef68eb3e0b4a0810f80b3951124d9ee6d7 | |
parent | c65d50681117edb96f6b1387f5a88de160811d38 (diff) | |
download | dexon-solidity-9f328ff749477106a569e679e5eeed5c7e78d29d.tar.gz dexon-solidity-9f328ff749477106a569e679e5eeed5c7e78d29d.tar.zst dexon-solidity-9f328ff749477106a569e679e5eeed5c7e78d29d.zip |
Turn non-constant constants error into warning.
-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) |