aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-06-26 15:13:41 +0800
committerGitHub <noreply@github.com>2017-06-26 15:13:41 +0800
commitf879489291b78a7872c13d3235e1d345883880b4 (patch)
tree42b0df78242412d4b620579f5eb2b4db4b6e2d85 /test/libsolidity
parent29b8cdb594044525b398994fe9855fbbdb76981b (diff)
parent7a3ea61ffd226cc09ef419c47c0506699aa69b50 (diff)
downloaddexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar.gz
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar.bz2
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar.lz
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar.xz
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.tar.zst
dexon-solidity-f879489291b78a7872c13d3235e1d345883880b4.zip
Merge pull request #2449 from federicobond/warn-bytesxx-decimal
Warn if decimal literals are used in a bytesXX context
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp34
1 files changed, 32 insertions, 2 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 9775d6d0..e18303f5 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -2183,6 +2183,36 @@ BOOST_AUTO_TEST_CASE(test_byte_is_alias_of_byte1)
ETH_TEST_REQUIRE_NO_THROW(parseAndAnalyse(text), "Type resolving failed");
}
+BOOST_AUTO_TEST_CASE(warns_assigning_decimal_to_bytesxx)
+{
+ char const* text = R"(
+ contract Foo {
+ bytes32 a = 7;
+ }
+ )";
+ CHECK_WARNING(text, "Decimal literal assigned to bytesXX variable will be left-aligned.");
+}
+
+BOOST_AUTO_TEST_CASE(does_not_warn_assigning_hex_number_to_bytesxx)
+{
+ char const* text = R"(
+ contract Foo {
+ bytes32 a = 0x1234;
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+}
+
+BOOST_AUTO_TEST_CASE(explicit_conversion_from_decimal_to_bytesxx)
+{
+ char const* text = R"(
+ contract Foo {
+ bytes32 a = bytes32(7);
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+}
+
BOOST_AUTO_TEST_CASE(assigning_value_to_const_variable)
{
char const* text = R"(
@@ -3718,12 +3748,12 @@ BOOST_AUTO_TEST_CASE(conditional_with_all_types)
byte[2] memory a;
byte[2] memory b;
var k = true ? a : b;
- k[0] = 0; //Avoid unused var warning
+ k[0] = byte(0); //Avoid unused var warning
bytes memory e;
bytes memory f;
var l = true ? e : f;
- l[0] = 0; // Avoid unused var warning
+ l[0] = byte(0); // Avoid unused var warning
// fixed bytes
bytes2 c;