aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Changelog.md1
-rw-r--r--libsolidity/ast/Types.cpp18
-rw-r--r--libsolidity/ast/Types.h4
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp4
4 files changed, 23 insertions, 4 deletions
diff --git a/Changelog.md b/Changelog.md
index 3bdd366d..ab1b35cd 100644
--- a/Changelog.md
+++ b/Changelog.md
@@ -14,6 +14,7 @@ Features:
* Type Checker: Issue warning for using ``public`` visibility for interface functions.
Bugfixes:
+ * Error Output: Truncate huge number literals in the middle to avoid output blow-up.
* Parser: Disallow event declarations with no parameter list.
* Standard JSON: Populate the ``sourceLocation`` field in the error list.
* Standard JSON: Properly support contract and library file names containing a colon (such as URLs).
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index 21daac2c..e4b7e4fd 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -949,11 +949,25 @@ bool RationalNumberType::operator==(Type const& _other) const
return m_value == other.m_value;
}
+string RationalNumberType::bigintToReadableString(dev::bigint const& _num)
+{
+ string str = _num.str();
+ if (str.size() > 32)
+ {
+ int omitted = str.size() - 8;
+ str = str.substr(0, 4) + "...(" + to_string(omitted) + " digits omitted)..." + str.substr(str.size() - 4, 4);
+ }
+ return str;
+}
+
string RationalNumberType::toString(bool) const
{
if (!isFractional())
- return "int_const " + m_value.numerator().str();
- return "rational_const " + m_value.numerator().str() + '/' + m_value.denominator().str();
+ return "int_const " + bigintToReadableString(m_value.numerator());
+
+ string numerator = bigintToReadableString(m_value.numerator());
+ string denominator = bigintToReadableString(m_value.denominator());
+ return "rational_const " + numerator + " / " + denominator;
}
u256 RationalNumberType::literalValue(Literal const*) const
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index a54e4e09..2e7d05ba 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -437,6 +437,10 @@ private:
/// @returns true if the literal is a valid rational number.
static std::tuple<bool, rational> parseRational(std::string const& _value);
+
+ /// @returns a truncated readable representation of the bigint keeping only
+ /// up to 4 leading and 4 trailing digits.
+ static std::string bigintToReadableString(dev::bigint const& num);
};
/**
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 1953195c..e757c755 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -1752,7 +1752,7 @@ BOOST_AUTO_TEST_CASE(overflow_caused_by_ether_units)
uint256 a;
}
)";
- CHECK_ERROR(sourceCode, TypeError, "Type int_const 115792089237316195423570985008687907853269984665640564039458000000000000000000 is not implicitly convertible to expected type uint256.");
+ CHECK_ERROR(sourceCode, TypeError, "Type int_const 1157...(70 digits omitted)...0000 is not implicitly convertible to expected type uint256.");
}
BOOST_AUTO_TEST_CASE(exp_operator_exponent_too_big)
@@ -4586,7 +4586,7 @@ BOOST_AUTO_TEST_CASE(rational_index_access)
}
}
)";
- CHECK_ERROR(text, TypeError, "rational_const 1/2 is not implicitly convertible to expected type uint256");
+ CHECK_ERROR(text, TypeError, "rational_const 1 / 2 is not implicitly convertible to expected type uint256");
}
BOOST_AUTO_TEST_CASE(rational_to_fixed_literal_expression)