aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-04-23 21:54:45 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-04-23 23:19:51 +0800
commit1ac0090f31d12a720950991ab4e85710877effd1 (patch)
tree4c084c0f90d9d3b5551fdaeeaa0599d0147acb01
parent75faed7c55a45770b6b56fa9fe2be308604030a0 (diff)
downloaddexon-solidity-1ac0090f31d12a720950991ab4e85710877effd1.tar.gz
dexon-solidity-1ac0090f31d12a720950991ab4e85710877effd1.tar.zst
dexon-solidity-1ac0090f31d12a720950991ab4e85710877effd1.zip
The "year" denomination is deprecated
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/analysis/TypeChecker.cpp16
-rw-r--r--test/libsolidity/syntaxTests/denominations/denominations.sol2
-rw-r--r--test/libsolidity/syntaxTests/denominations/deprecated_year.sol5
-rw-r--r--test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol6
5 files changed, 30 insertions, 0 deletions
diff --git a/Changelog.md b/Changelog.md
index f51bd634..4787f1c8 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -3,6 +3,7 @@
Features:
* Build System: Update internal dependency of jsoncpp to 1.8.4, which introduces more strictness and reduces memory usage.
* Optimizer: Remove unnecessary masking of the result of known short instructions (``ADDRESS``, ``CALLER``, ``ORIGIN`` and ``COINBASE``).
+ * Type Checker: Deprecate the ``years`` unit denomination and raise a warning for it (or an error as experimental 0.5.0 feature).
* Type Checker: Make literals (without explicit type casting) an error for tight packing as experimental 0.5.0 feature.
Bugfixes:
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 40162322..a672cd66 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -2220,6 +2220,7 @@ void TypeChecker::endVisit(Literal const& _literal)
"For more information please see https://solidity.readthedocs.io/en/develop/types.html#address-literals"
);
}
+
if (_literal.isHexNumber() && _literal.subDenomination() != Literal::SubDenomination::None)
{
if (v050)
@@ -2235,6 +2236,21 @@ void TypeChecker::endVisit(Literal const& _literal)
"You can use an expression of the form \"0x1234 * 1 day\" instead."
);
}
+
+ if (_literal.subDenomination() == Literal::SubDenomination::Year)
+ {
+ if (v050)
+ m_errorReporter.typeError(
+ _literal.location(),
+ "Using \"years\" as a unit denomination is deprecated."
+ );
+ else
+ m_errorReporter.warning(
+ _literal.location(),
+ "Using \"years\" as a unit denomination is deprecated."
+ );
+ }
+
if (!_literal.annotation().type)
_literal.annotation().type = Type::forLiteral(_literal);
diff --git a/test/libsolidity/syntaxTests/denominations/denominations.sol b/test/libsolidity/syntaxTests/denominations/denominations.sol
index de9f73e1..6d1aa2f3 100644
--- a/test/libsolidity/syntaxTests/denominations/denominations.sol
+++ b/test/libsolidity/syntaxTests/denominations/denominations.sol
@@ -3,3 +3,5 @@ contract C {
uint constant b = 1 seconds + 2 minutes + 3 hours + 4 days + 5 weeks + 6 years;
uint constant c = 2 szabo / 1 seconds + 3 finney * 3 hours;
}
+// ----
+// Warning: (142-149): Using "years" as a unit denomination is deprecated.
diff --git a/test/libsolidity/syntaxTests/denominations/deprecated_year.sol b/test/libsolidity/syntaxTests/denominations/deprecated_year.sol
new file mode 100644
index 00000000..30e86535
--- /dev/null
+++ b/test/libsolidity/syntaxTests/denominations/deprecated_year.sol
@@ -0,0 +1,5 @@
+contract C {
+ uint constant a = 3 years;
+}
+// ----
+// Warning: (32-39): Using "years" as a unit denomination is deprecated.
diff --git a/test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol b/test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol
new file mode 100644
index 00000000..4baaeaa3
--- /dev/null
+++ b/test/libsolidity/syntaxTests/denominations/deprecated_year_050.sol
@@ -0,0 +1,6 @@
+pragma experimental "v0.5.0";
+contract C {
+ uint constant a = 3 years;
+}
+// ----
+// TypeError: (62-69): Using "years" as a unit denomination is deprecated.