mirror of
https://github.com/ethereum/solidity
synced 2023-10-03 13:03:40 +00:00
Merge pull request #3956 from ethereum/tight-pack-hash
Make literals an error for tight packing (experimental 0.5.0)
This commit is contained in:
commit
72b0412ef6
@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Features:
|
Features:
|
||||||
* Optimizer: Remove unnecessary masking of the result of known short instructions (``ADDRESS``, ``CALLER``, ``ORIGIN`` and ``COINBASE``).
|
* Optimizer: Remove unnecessary masking of the result of known short instructions (``ADDRESS``, ``CALLER``, ``ORIGIN`` and ``COINBASE``).
|
||||||
|
* Type Checker: Make literals (without explicit type casting) an error for tight packing as experimental 0.5.0 feature.
|
||||||
|
|
||||||
Bugfixes:
|
Bugfixes:
|
||||||
|
|
||||||
|
@ -1648,6 +1648,8 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
|||||||
else
|
else
|
||||||
_functionCall.annotation().type = make_shared<TupleType>(returnTypes);
|
_functionCall.annotation().type = make_shared<TupleType>(returnTypes);
|
||||||
|
|
||||||
|
bool const v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
|
||||||
|
|
||||||
if (auto functionName = dynamic_cast<Identifier const*>(&_functionCall.expression()))
|
if (auto functionName = dynamic_cast<Identifier const*>(&_functionCall.expression()))
|
||||||
{
|
{
|
||||||
if (functionName->name() == "sha3" && functionType->kind() == FunctionType::Kind::SHA3)
|
if (functionName->name() == "sha3" && functionType->kind() == FunctionType::Kind::SHA3)
|
||||||
@ -1674,6 +1676,13 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
|||||||
{
|
{
|
||||||
/* If no mobile type is available an error will be raised elsewhere. */
|
/* If no mobile type is available an error will be raised elsewhere. */
|
||||||
if (literal->mobileType())
|
if (literal->mobileType())
|
||||||
|
{
|
||||||
|
if (v050)
|
||||||
|
m_errorReporter.typeError(
|
||||||
|
arguments[i]->location(),
|
||||||
|
"Cannot perform packed encoding for a literal. Please convert it to an explicit type first."
|
||||||
|
);
|
||||||
|
else
|
||||||
m_errorReporter.warning(
|
m_errorReporter.warning(
|
||||||
arguments[i]->location(),
|
arguments[i]->location(),
|
||||||
"The type of \"" +
|
"The type of \"" +
|
||||||
@ -1685,6 +1694,7 @@ bool TypeChecker::visit(FunctionCall const& _functionCall)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (functionType->takesArbitraryParameters() && arguments.size() < parameterTypes.size())
|
if (functionType->takesArbitraryParameters() && arguments.size() < parameterTypes.size())
|
||||||
{
|
{
|
||||||
|
26
test/libsolidity/syntaxTests/tight_packing_literals_050.sol
Normal file
26
test/libsolidity/syntaxTests/tight_packing_literals_050.sol
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
pragma experimental "v0.5.0";
|
||||||
|
contract C {
|
||||||
|
function f() pure public returns (bytes32) {
|
||||||
|
return keccak256(1);
|
||||||
|
}
|
||||||
|
function g() pure public returns (bytes32) {
|
||||||
|
return sha3(1);
|
||||||
|
}
|
||||||
|
function h() pure public returns (bytes32) {
|
||||||
|
return sha256(1);
|
||||||
|
}
|
||||||
|
function j() pure public returns (bytes32) {
|
||||||
|
return ripemd160(1);
|
||||||
|
}
|
||||||
|
function k() pure public returns (bytes) {
|
||||||
|
return abi.encodePacked(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// ----
|
||||||
|
// TypeError: (117-118): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
|
||||||
|
// Warning: (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: (277-278): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
|
||||||
|
// TypeError: (361-362): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
|
||||||
|
// TypeError: (450-451): Cannot perform packed encoding for a literal. Please convert it to an explicit type first.
|
@ -2,10 +2,21 @@ contract C {
|
|||||||
function f() pure public returns (bytes32) {
|
function f() pure public returns (bytes32) {
|
||||||
return keccak256(uint8(1));
|
return keccak256(uint8(1));
|
||||||
}
|
}
|
||||||
function g() pure public returns (bytes) {
|
function g() pure public returns (bytes32) {
|
||||||
return abi.encode(1);
|
return sha3(uint8(1));
|
||||||
}
|
}
|
||||||
function h() pure public returns (bytes) {
|
function h() pure public returns (bytes32) {
|
||||||
|
return sha256(uint8(1));
|
||||||
|
}
|
||||||
|
function j() pure public returns (bytes32) {
|
||||||
|
return ripemd160(uint8(1));
|
||||||
|
}
|
||||||
|
function k() pure public returns (bytes) {
|
||||||
return abi.encodePacked(uint8(1));
|
return abi.encodePacked(uint8(1));
|
||||||
}
|
}
|
||||||
|
function l() pure public returns (bytes) {
|
||||||
|
return abi.encode(1);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// ----
|
||||||
|
// Warning: (168-182): "sha3" has been deprecated in favour of "keccak256"
|
||||||
|
Loading…
Reference in New Issue
Block a user