aboutsummaryrefslogtreecommitdiffstats
path: root/test/libsolidity
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2017-08-25 19:17:44 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2017-08-25 21:16:50 +0800
commitf6dba97fe174c95f9dd5defdd8f443c121f73956 (patch)
tree88685e47c9a7ee058ed124badc66241e9e50dc81 /test/libsolidity
parent1437521df0136fc3654dd74c816d724c50a125ee (diff)
downloaddexon-solidity-f6dba97fe174c95f9dd5defdd8f443c121f73956.tar.gz
dexon-solidity-f6dba97fe174c95f9dd5defdd8f443c121f73956.tar.zst
dexon-solidity-f6dba97fe174c95f9dd5defdd8f443c121f73956.zip
Warn on using literals in tight packing
Diffstat (limited to 'test/libsolidity')
-rw-r--r--test/libsolidity/SolidityNameAndTypeResolution.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/test/libsolidity/SolidityNameAndTypeResolution.cpp b/test/libsolidity/SolidityNameAndTypeResolution.cpp
index 380978e8..15b06125 100644
--- a/test/libsolidity/SolidityNameAndTypeResolution.cpp
+++ b/test/libsolidity/SolidityNameAndTypeResolution.cpp
@@ -6744,6 +6744,50 @@ BOOST_AUTO_TEST_CASE(reject_interface_constructors)
CHECK_ERROR(text, TypeError, "Wrong argument count for constructor call: 1 arguments given but expected 0.");
}
+BOOST_AUTO_TEST_CASE(tight_packing_literals)
+{
+ char const* text = R"(
+ contract C {
+ function f() returns (bytes32) {
+ return keccak256(1);
+ }
+ }
+ )";
+ CHECK_WARNING(text, "The type of \"int_const 1\" was inferred as uint8.");
+ text = R"(
+ contract C {
+ function f() returns (bytes32) {
+ return keccak256(uint8(1));
+ }
+ }
+ )";
+ CHECK_SUCCESS_NO_WARNINGS(text);
+ text = R"(
+ contract C {
+ function f() returns (bytes32) {
+ return sha3(1);
+ }
+ }
+ )";
+ CHECK_WARNING(text, "The type of \"int_const 1\" was inferred as uint8.");
+ text = R"(
+ contract C {
+ function f() returns (bytes32) {
+ return sha256(1);
+ }
+ }
+ )";
+ CHECK_WARNING(text, "The type of \"int_const 1\" was inferred as uint8.");
+ text = R"(
+ contract C {
+ function f() returns (bytes32) {
+ return ripemd160(1);
+ }
+ }
+ )";
+ CHECK_WARNING(text, "The type of \"int_const 1\" was inferred as uint8.");
+}
+
BOOST_AUTO_TEST_SUITE_END()
}