Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion libsolidity/analysis/StaticAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,23 @@ 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 (m_nonPayablePublic && !m_library)
if (MagicType const* type = dynamic_cast<MagicType const*>(_memberAccess.expression().annotation().type.get()))
if (type->kind() == MagicType::Kind::Message && _memberAccess.memberName() == "value")
Expand All @@ -151,7 +168,7 @@ bool StaticAnalyzer::visit(MemberAccess const& _memberAccess)
if (auto const* type = dynamic_cast<FunctionType const*>(_memberAccess.annotation().type.get()))
if (type->kind() == FunctionType::Kind::BareCallCode)
{
if (m_currentContract->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
if (v050)
m_errorReporter.typeError(
_memberAccess.location(),
"\"callcode\" has been deprecated in favour of \"delegatecall\"."
Expand Down
14 changes: 4 additions & 10 deletions libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3000,10 +3000,8 @@ bool MagicType::operator==(Type const& _other) const
return other.m_kind == m_kind;
}

MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const* _contract) const
MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const*) const
{
solAssert(_contract, "");
const bool v050 = _contract->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050);
switch (m_kind)
{
case Kind::Block:
Expand All @@ -3016,17 +3014,13 @@ MemberList::MemberMap MagicType::nativeMembers(ContractDefinition const* _contra
{"gaslimit", make_shared<IntegerType>(256)}
});
case Kind::Message:
{
std::vector<MemberList::Member> members = {
return MemberList::MemberMap({
{"sender", make_shared<IntegerType>(160, IntegerType::Modifier::Address)},
{"gas", make_shared<IntegerType>(256)},
{"value", make_shared<IntegerType>(256)},
{"data", make_shared<ArrayType>(DataLocation::CallData)},
{"sig", make_shared<FixedBytesType>(4)}
};
if (!v050)
members.emplace_back("gas", make_shared<IntegerType>(256));
return members;
}
});
case Kind::Transaction:
return MemberList::MemberMap({
{"origin", make_shared<IntegerType>(160, IntegerType::Modifier::Address)},
Expand Down
5 changes: 0 additions & 5 deletions libsolidity/codegen/ExpressionCompiler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -924,8 +924,6 @@ bool ExpressionCompiler::visit(NewExpression const&)

bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
{
bool const v050 = m_context.experimentalFeatureActive(ExperimentalFeature::V050);

CompilerContext::LocationSetter locationSetter(m_context, _memberAccess);
// Check whether the member is a bound function.
ASTString const& member = _memberAccess.memberName();
Expand Down Expand Up @@ -1141,10 +1139,7 @@ bool ExpressionCompiler::visit(MemberAccess const& _memberAccess)
else if (member == "origin")
m_context << Instruction::ORIGIN;
else if (member == "gas")
{
solAssert(!v050, "");
m_context << Instruction::GAS;
}
else if (member == "gasprice")
m_context << Instruction::GASPRICE;
else if (member == "data")
Expand Down
4 changes: 2 additions & 2 deletions test/libsolidity/SolidityNameAndTypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7416,7 +7416,7 @@ BOOST_AUTO_TEST_CASE(gasleft)
function f() public view returns (uint256 val) { return msg.gas; }
}
)";
CHECK_SUCCESS_NO_WARNINGS(text);
CHECK_WARNING(text, "\"msg.gas\" has been deprecated in favor of \"gasleft()\"");

text = R"(
contract C {
Expand All @@ -7431,7 +7431,7 @@ BOOST_AUTO_TEST_CASE(gasleft)
function f() public returns (uint256 val) { return msg.gas; }
}
)";
CHECK_ERROR(text, TypeError, "Member \"gas\" not found or not visible after argument-dependent lookup in msg");
CHECK_ERROR(text, TypeError, "\"msg.gas\" has been deprecated in favor of \"gasleft()\"");
}

BOOST_AUTO_TEST_CASE(gasleft_shadowing)
Expand Down