aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-06-25 22:54:50 +0800
committerGitHub <noreply@github.com>2018-06-25 22:54:50 +0800
commit0ac46090971aab21120875e0e55317e4bd2b397e (patch)
treea027ddad46f3c20ef7d3b013b230083895c81db5 /libsolidity
parentb7003505c46942ca2ee4e5317d14f421d5b9bc6d (diff)
parent6d9a091a8e0c7e5a958ff910c9f8dc828a39e0e4 (diff)
downloaddexon-solidity-0ac46090971aab21120875e0e55317e4bd2b397e.tar.gz
dexon-solidity-0ac46090971aab21120875e0e55317e4bd2b397e.tar.zst
dexon-solidity-0ac46090971aab21120875e0e55317e4bd2b397e.zip
Merge pull request #3534 from meowingtwurtle/strictAddresses
[BREAKING] Strict checking of address literals
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/analysis/TypeChecker.cpp28
-rw-r--r--libsolidity/ast/Types.cpp6
2 files changed, 25 insertions, 9 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index 19e931f2..b46d4849 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -2287,14 +2287,28 @@ void TypeChecker::endVisit(Literal const& _literal)
if (_literal.looksLikeAddress())
{
- if (_literal.passesAddressChecksum())
- _literal.annotation().type = make_shared<IntegerType>(160, IntegerType::Modifier::Address);
- else
- m_errorReporter.warning(
+ // Assign type here if it even looks like an address. This prevents double error in 050 mode for invalid address
+ _literal.annotation().type = make_shared<IntegerType>(160, IntegerType::Modifier::Address);
+
+ string msg;
+ if (_literal.value().length() != 42) // "0x" + 40 hex digits
+ // looksLikeAddress enforces that it is a hex literal starting with "0x"
+ msg =
+ "This looks like an address but is not exactly 40 hex digits. It is " +
+ to_string(_literal.value().length() - 2) +
+ " hex digits.";
+ else if (!_literal.passesAddressChecksum())
+ {
+ msg = "This looks like an address but has an invalid checksum.";
+ if (!_literal.getChecksummedAddress().empty())
+ msg += " Correct checksummed address: \"" + _literal.getChecksummedAddress() + "\".";
+ }
+
+ if (!msg.empty())
+ m_errorReporter.syntaxError(
_literal.location(),
- "This looks like an address but has an invalid checksum. "
- "If this is not used as an address, please prepend '00'. " +
- (!_literal.getChecksummedAddress().empty() ? "Correct checksummed address: '" + _literal.getChecksummedAddress() + "'. " : "") +
+ msg +
+ " If this is not used as an address, please prepend '00'. " +
"For more information please see https://solidity.readthedocs.io/en/develop/types.html#address-literals"
);
}
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index c4d97c64..68c53af1 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -858,11 +858,13 @@ bool RationalNumberType::isImplicitlyConvertibleTo(Type const& _convertTo) const
{
if (_convertTo.category() == Category::Integer)
{
- if (m_value == rational(0))
- return true;
if (isFractional())
return false;
IntegerType const& targetType = dynamic_cast<IntegerType const&>(_convertTo);
+ if (targetType.isAddress())
+ return false;
+ if (m_value == rational(0))
+ return true;
unsigned forSignBit = (targetType.isSigned() ? 1 : 0);
if (m_value > rational(0))
{