aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Beregszaszi <alex@rtfs.hu>2018-05-16 17:12:25 +0800
committerAlex Beregszaszi <alex@rtfs.hu>2018-05-16 17:12:25 +0800
commit221a4d1f1f8a644ef9905f8f1d4a9a4428ec0489 (patch)
tree46b41743c2057f2ea8dd08619337ca1905bd1483
parent23adea88fdc7eafc5b67b759b4c2418bd6b93aa6 (diff)
downloaddexon-solidity-221a4d1f1f8a644ef9905f8f1d4a9a4428ec0489.tar
dexon-solidity-221a4d1f1f8a644ef9905f8f1d4a9a4428ec0489.tar.gz
dexon-solidity-221a4d1f1f8a644ef9905f8f1d4a9a4428ec0489.tar.bz2
dexon-solidity-221a4d1f1f8a644ef9905f8f1d4a9a4428ec0489.tar.lz
dexon-solidity-221a4d1f1f8a644ef9905f8f1d4a9a4428ec0489.tar.xz
dexon-solidity-221a4d1f1f8a644ef9905f8f1d4a9a4428ec0489.tar.zst
dexon-solidity-221a4d1f1f8a644ef9905f8f1d4a9a4428ec0489.zip
Split warning for multi arguments for hash functions
-rw-r--r--libsolidity/analysis/TypeChecker.cpp22
-rw-r--r--test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol3
-rw-r--r--test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol3
-rw-r--r--test/libsolidity/syntaxTests/deprecated_functions_050.sol3
-rw-r--r--test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol9
-rw-r--r--test/libsolidity/syntaxTests/tight_packing_literals.sol12
-rw-r--r--test/libsolidity/syntaxTests/tight_packing_literals_050.sol12
-rw-r--r--test/libsolidity/syntaxTests/tight_packing_literals_fine.sol12
8 files changed, 48 insertions, 28 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp
index f77cc60c..30302908 100644
--- a/libsolidity/analysis/TypeChecker.cpp
+++ b/libsolidity/analysis/TypeChecker.cpp
@@ -1762,22 +1762,24 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
if (functionType->takesSinglePackedBytesParameter())
{
- string generalMessage =
- "This function only accepts a single \"bytes\" argument. Please use "
- "\"abi.encodePacked(...)\" or a similar function to encode the data.";
-
- if (arguments.size() > 1)
+ if (
+ (arguments.size() > 1) ||
+ (arguments.size() == 1 && !type(*arguments.front())->isImplicitlyConvertibleTo(ArrayType(DataLocation::Memory)))
+ )
{
+ string msg =
+ "This function only accepts a single \"bytes\" argument. Please use "
+ "\"abi.encodePacked(...)\" or a similar function to encode the data.";
if (v050)
- m_errorReporter.typeError(_functionCall.location(), generalMessage);
+ m_errorReporter.typeError(_functionCall.location(), msg);
else
- m_errorReporter.warning(_functionCall.location(), generalMessage);
+ m_errorReporter.warning(_functionCall.location(), msg);
}
- else if (arguments.size() == 1 && !type(*arguments.front())->isImplicitlyConvertibleTo(ArrayType(DataLocation::Memory)))
+
+ if (arguments.size() == 1 && !type(*arguments.front())->isImplicitlyConvertibleTo(ArrayType(DataLocation::Memory)))
{
string msg =
- generalMessage +
- " The provided argument of type " +
+ "The provided argument of type " +
type(*arguments.front())->toString() +
" is not implicitly convertible to expected type bytes memory.";
if (v050)
diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol
index 0728c962..08d20c3a 100644
--- a/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol
+++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_2.sol
@@ -5,7 +5,8 @@ contract C {
uint constant d = 2 + a;
}
// ----
-// Warning: (98-110): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint256 is not implicitly convertible to expected type bytes memory.
+// Warning: (98-110): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (98-110): The provided argument of type uint256 is not implicitly convertible to expected type bytes memory.
// TypeError: (17-40): The value of the constant a has a cyclic dependency via c.
// TypeError: (71-111): The value of the constant c has a cyclic dependency via d.
// TypeError: (117-140): The value of the constant d has a cyclic dependency via a.
diff --git a/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol b/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol
index 8954e6a3..df5cd969 100644
--- a/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol
+++ b/test/libsolidity/syntaxTests/constants/cyclic_dependency_4.sol
@@ -5,4 +5,5 @@ contract C {
uint constant d = 2 + b;
}
// ----
-// Warning: (98-110): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint256 is not implicitly convertible to expected type bytes memory.
+// Warning: (98-110): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (98-110): The provided argument of type uint256 is not implicitly convertible to expected type bytes memory.
diff --git a/test/libsolidity/syntaxTests/deprecated_functions_050.sol b/test/libsolidity/syntaxTests/deprecated_functions_050.sol
index 92973c5f..b28e5abb 100644
--- a/test/libsolidity/syntaxTests/deprecated_functions_050.sol
+++ b/test/libsolidity/syntaxTests/deprecated_functions_050.sol
@@ -10,5 +10,6 @@ contract test {
}
// ----
// TypeError: (88-102): "sha3" has been deprecated in favour of "keccak256"
-// TypeError: (88-102): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
+// TypeError: (88-102): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// TypeError: (88-102): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
// TypeError: (137-147): "suicide" has been deprecated in favour of "selfdestruct"
diff --git a/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol b/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol
index 3f8e3014..a6ee4bf1 100644
--- a/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol
+++ b/test/libsolidity/syntaxTests/specialFunctions/single_non_bytes_arg.sol
@@ -7,6 +7,9 @@ contract C {
function g(bytes32) pure internal {}
}
// ----
-// Warning: (54-72): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint256 is not implicitly convertible to expected type bytes memory.
-// Warning: (85-100): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint256 is not implicitly convertible to expected type bytes memory.
-// Warning: (113-131): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint256 is not implicitly convertible to expected type bytes memory.
+// Warning: (54-72): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (54-72): The provided argument of type uint256 is not implicitly convertible to expected type bytes memory.
+// Warning: (85-100): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (85-100): The provided argument of type uint256 is not implicitly convertible to expected type bytes memory.
+// Warning: (113-131): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (113-131): The provided argument of type uint256 is not implicitly convertible to expected type bytes memory.
diff --git a/test/libsolidity/syntaxTests/tight_packing_literals.sol b/test/libsolidity/syntaxTests/tight_packing_literals.sol
index 202a3202..a190adc3 100644
--- a/test/libsolidity/syntaxTests/tight_packing_literals.sol
+++ b/test/libsolidity/syntaxTests/tight_packing_literals.sol
@@ -18,12 +18,16 @@ contract C {
// ----
// Warning: (87-88): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
-// Warning: (77-89): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
+// Warning: (77-89): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (77-89): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// Warning: (161-168): "sha3" has been deprecated in favour of "keccak256"
// Warning: (166-167): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
-// Warning: (161-168): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
+// Warning: (161-168): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (161-168): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// Warning: (247-248): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
-// Warning: (240-249): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
+// Warning: (240-249): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (240-249): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// Warning: (331-332): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
-// Warning: (321-333): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
+// Warning: (321-333): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (321-333): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// Warning: (420-421): The type of "int_const 1" was inferred as uint8. This is probably not desired. Use an explicit type to silence this warning.
diff --git a/test/libsolidity/syntaxTests/tight_packing_literals_050.sol b/test/libsolidity/syntaxTests/tight_packing_literals_050.sol
index fcf8ec50..b7557d2a 100644
--- a/test/libsolidity/syntaxTests/tight_packing_literals_050.sol
+++ b/test/libsolidity/syntaxTests/tight_packing_literals_050.sol
@@ -19,12 +19,16 @@ contract C {
// ----
// TypeError: (117-118): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
-// TypeError: (107-119): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
+// TypeError: (107-119): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// TypeError: (107-119): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// TypeError: (191-198): "sha3" has been deprecated in favour of "keccak256"
// TypeError: (196-197): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
-// TypeError: (191-198): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
+// TypeError: (191-198): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// TypeError: (191-198): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// TypeError: (277-278): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
-// TypeError: (270-279): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
+// TypeError: (270-279): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// TypeError: (270-279): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// TypeError: (361-362): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
-// TypeError: (351-363): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
+// TypeError: (351-363): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// TypeError: (351-363): The provided argument of type int_const 1 is not implicitly convertible to expected type bytes memory.
// TypeError: (450-451): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
diff --git a/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol b/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol
index e18fbd9f..2b9b688a 100644
--- a/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol
+++ b/test/libsolidity/syntaxTests/tight_packing_literals_fine.sol
@@ -19,8 +19,12 @@ contract C {
}
}
// ----
-// Warning: (77-96): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
+// Warning: (77-96): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (77-96): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
// Warning: (168-182): "sha3" has been deprecated in favour of "keccak256"
-// Warning: (168-182): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
-// Warning: (254-270): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
-// Warning: (342-361): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data. The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
+// Warning: (168-182): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (168-182): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
+// Warning: (254-270): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (254-270): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.
+// Warning: (342-361): This function only accepts a single "bytes" argument. Please use "abi.encodePacked(...)" or a similar function to encode the data.
+// Warning: (342-361): The provided argument of type uint8 is not implicitly convertible to expected type bytes memory.