aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonardo Alt <leo@ethereum.org>2018-07-04 17:42:05 +0800
committerLeonardo Alt <leo@ethereum.org>2018-07-04 17:42:05 +0800
commit8202d512e0bd4e6b4a19ed483afff288514e75bd (patch)
tree126d4afb677ecd531532573f22be95090145f48f
parent533d5d4b1cc4374decc704de8c86ad4cef6214fc (diff)
downloaddexon-solidity-8202d512e0bd4e6b4a19ed483afff288514e75bd.tar
dexon-solidity-8202d512e0bd4e6b4a19ed483afff288514e75bd.tar.gz
dexon-solidity-8202d512e0bd4e6b4a19ed483afff288514e75bd.tar.bz2
dexon-solidity-8202d512e0bd4e6b4a19ed483afff288514e75bd.tar.lz
dexon-solidity-8202d512e0bd4e6b4a19ed483afff288514e75bd.tar.xz
dexon-solidity-8202d512e0bd4e6b4a19ed483afff288514e75bd.tar.zst
dexon-solidity-8202d512e0bd4e6b4a19ed483afff288514e75bd.zip
Enforcing error on msg.gas and block.blockhash()
-rw-r--r--libsolidity/analysis/StaticAnalyzer.cpp36
-rw-r--r--test/libsolidity/SolidityEndToEndTest.cpp2
-rw-r--r--test/libsolidity/SolidityExpressionCompiler.cpp19
-rw-r--r--test/libsolidity/ViewPureChecker.cpp11
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/498_msg_gas_deprecated.sol2
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/499_msg_gas_deprecated_v050.sol6
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/569_block_blockhash_deprecated.sol2
-rw-r--r--test/libsolidity/syntaxTests/nameAndTypeResolution/570_block_blockhash_deprecated_v050.sol6
-rw-r--r--test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol4
9 files changed, 20 insertions, 68 deletions
diff --git a/libsolidity/analysis/StaticAnalyzer.cpp b/libsolidity/analysis/StaticAnalyzer.cpp
index c7440565..323282ca 100644
--- a/libsolidity/analysis/StaticAnalyzer.cpp
+++ b/libsolidity/analysis/StaticAnalyzer.cpp
@@ -150,36 +150,18 @@ bool StaticAnalyzer::visit(ExpressionStatement const& _statement)
bool StaticAnalyzer::visit(MemberAccess const& _memberAccess)
{
- bool const v050 = m_currentContract->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
-
if (MagicType const* type = dynamic_cast<MagicType const*>(_memberAccess.expression().annotation().type.get()))
{
if (type->kind() == MagicType::Kind::Message && _memberAccess.memberName() == "gas")
- {
- if (v050)
- m_errorReporter.typeError(
- _memberAccess.location(),
- "\"msg.gas\" has been deprecated in favor of \"gasleft()\""
- );
- else
- m_errorReporter.warning(
- _memberAccess.location(),
- "\"msg.gas\" has been deprecated in favor of \"gasleft()\""
- );
- }
- if (type->kind() == MagicType::Kind::Block && _memberAccess.memberName() == "blockhash")
- {
- if (v050)
- m_errorReporter.typeError(
- _memberAccess.location(),
- "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\""
- );
- else
- m_errorReporter.warning(
- _memberAccess.location(),
- "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\""
- );
- }
+ m_errorReporter.typeError(
+ _memberAccess.location(),
+ "\"msg.gas\" has been deprecated in favor of \"gasleft()\""
+ );
+ else if (type->kind() == MagicType::Kind::Block && _memberAccess.memberName() == "blockhash")
+ m_errorReporter.typeError(
+ _memberAccess.location(),
+ "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\""
+ );
}
if (m_nonPayablePublic && !m_library)
diff --git a/test/libsolidity/SolidityEndToEndTest.cpp b/test/libsolidity/SolidityEndToEndTest.cpp
index 9e6aa43d..9622de8c 100644
--- a/test/libsolidity/SolidityEndToEndTest.cpp
+++ b/test/libsolidity/SolidityEndToEndTest.cpp
@@ -1856,7 +1856,7 @@ BOOST_AUTO_TEST_CASE(uncalled_blockhash)
contract C {
function f() public view returns (bytes32)
{
- return (block.blockhash)(block.number - 1);
+ return (blockhash)(block.number - 1);
}
}
)";
diff --git a/test/libsolidity/SolidityExpressionCompiler.cpp b/test/libsolidity/SolidityExpressionCompiler.cpp
index 2668dfdf..2ea0247e 100644
--- a/test/libsolidity/SolidityExpressionCompiler.cpp
+++ b/test/libsolidity/SolidityExpressionCompiler.cpp
@@ -524,31 +524,16 @@ BOOST_AUTO_TEST_CASE(gas_left)
char const* sourceCode = R"(
contract test {
function f() returns (uint256 val) {
- return msg.gas;
- }
- }
- )";
- bytes code = compileFirstExpression(
- sourceCode, {}, {},
- {make_shared<MagicVariableDeclaration>("msg", make_shared<MagicType>(MagicType::Kind::Message))}
- );
-
- bytes expectation({byte(Instruction::GAS)});
- BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
-
- sourceCode = R"(
- contract test {
- function f() returns (uint256 val) {
return gasleft();
}
}
)";
- code = compileFirstExpression(
+ bytes code = compileFirstExpression(
sourceCode, {}, {},
{make_shared<MagicVariableDeclaration>("gasleft", make_shared<FunctionType>(strings(), strings{"uint256"}, FunctionType::Kind::GasLeft))}
);
- expectation = bytes({byte(Instruction::GAS)});
+ bytes expectation = bytes({byte(Instruction::GAS)});
BOOST_CHECK_EQUAL_COLLECTIONS(code.begin(), code.end(), expectation.begin(), expectation.end());
}
diff --git a/test/libsolidity/ViewPureChecker.cpp b/test/libsolidity/ViewPureChecker.cpp
index 53761ff2..bb5480b2 100644
--- a/test/libsolidity/ViewPureChecker.cpp
+++ b/test/libsolidity/ViewPureChecker.cpp
@@ -43,13 +43,11 @@ BOOST_AUTO_TEST_CASE(environment_access)
vector<string> view{
"block.coinbase",
"block.timestamp",
- "block.blockhash(7)",
"block.difficulty",
"block.number",
"block.gaslimit",
"blockhash(7)",
"gasleft()",
- "msg.gas",
"msg.value",
"msg.sender",
"tx.origin",
@@ -90,12 +88,11 @@ BOOST_AUTO_TEST_CASE(environment_access)
"Statement has no effect."
}));
- CHECK_WARNING_ALLOW_MULTI(
+ CHECK_ERROR(
"contract C { function f() view public { block.blockhash; } }",
- (std::vector<std::string>{
- "Function state mutability can be restricted to pure",
- "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\""
- }));
+ TypeError,
+ "\"block.blockhash()\" has been deprecated in favor of \"blockhash()\""
+ );
}
BOOST_AUTO_TEST_CASE(assembly_staticcall)
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/498_msg_gas_deprecated.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/498_msg_gas_deprecated.sol
index d917b840..5efecd22 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/498_msg_gas_deprecated.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/498_msg_gas_deprecated.sol
@@ -2,4 +2,4 @@ contract C {
function f() public view returns (uint256 val) { return msg.gas; }
}
// ----
-// Warning: (73-80): "msg.gas" has been deprecated in favor of "gasleft()"
+// TypeError: (73-80): "msg.gas" has been deprecated in favor of "gasleft()"
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/499_msg_gas_deprecated_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/499_msg_gas_deprecated_v050.sol
deleted file mode 100644
index 31fd40da..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/499_msg_gas_deprecated_v050.sol
+++ /dev/null
@@ -1,6 +0,0 @@
-pragma experimental "v0.5.0";
-contract C {
- function f() public returns (uint256 val) { return msg.gas; }
-}
-// ----
-// TypeError: (98-105): "msg.gas" has been deprecated in favor of "gasleft()"
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/569_block_blockhash_deprecated.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/569_block_blockhash_deprecated.sol
index f2e5a2c4..b8f5d6a8 100644
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/569_block_blockhash_deprecated.sol
+++ b/test/libsolidity/syntaxTests/nameAndTypeResolution/569_block_blockhash_deprecated.sol
@@ -4,4 +4,4 @@ contract C {
}
}
// ----
-// Warning: (77-92): "block.blockhash()" has been deprecated in favor of "blockhash()"
+// TypeError: (77-92): "block.blockhash()" has been deprecated in favor of "blockhash()"
diff --git a/test/libsolidity/syntaxTests/nameAndTypeResolution/570_block_blockhash_deprecated_v050.sol b/test/libsolidity/syntaxTests/nameAndTypeResolution/570_block_blockhash_deprecated_v050.sol
deleted file mode 100644
index b954eab7..00000000
--- a/test/libsolidity/syntaxTests/nameAndTypeResolution/570_block_blockhash_deprecated_v050.sol
+++ /dev/null
@@ -1,6 +0,0 @@
-pragma experimental "v0.5.0";
-contract C {
- function f() public returns (bytes32) { return block.blockhash(3); }
-}
-// ----
-// TypeError: (94-109): "block.blockhash()" has been deprecated in favor of "blockhash()"
diff --git a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol
index b94a4391..a30e428a 100644
--- a/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol
+++ b/test/libsolidity/syntaxTests/specialFunctions/types_with_unspecified_encoding_internal_functions.sol
@@ -1,6 +1,6 @@
contract C {
function f() public pure {
- bytes32 h = keccak256(abi.encodePacked(keccak256, f, this.f.gas, block.blockhash));
+ bytes32 h = keccak256(abi.encodePacked(keccak256, f, this.f.gas, blockhash));
h;
}
}
@@ -8,4 +8,4 @@ contract C {
// TypeError: (91-100): This type cannot be encoded.
// TypeError: (102-103): This type cannot be encoded.
// TypeError: (105-115): This type cannot be encoded.
-// TypeError: (117-132): This type cannot be encoded.
+// TypeError: (117-126): This type cannot be encoded.