Skip to content

Commit

Permalink
Do not add members of address to contracts in experimental 0.5.0
Browse files Browse the repository at this point in the history
  • Loading branch information
axic committed Oct 2, 2017
1 parent 91b20b4 commit f734305
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
Features:
* Parser: Better error message for unexpected trailing comma in parameter lists.
* Syntax Checker: Unary ``+`` is now a syntax error as experimental 0.5.0 feature.
* Type Checker: Do not add members of ``address`` to contracts as experimental 0.5.0 feature.

Bugfixes:
* Parser: Fix source location of VariableDeclarationStatement.
Expand Down
3 changes: 3 additions & 0 deletions docs/types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ Operators:

* ``<=``, ``<``, ``==``, ``!=``, ``>=`` and ``>``

.. note::
Starting with version 0.5.0 contracts do not derive from the address type.

.. _members-of-addresses:

Members of Addresses
Expand Down
6 changes: 4 additions & 2 deletions libsolidity/ast/Types.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1616,7 +1616,7 @@ string ContractType::canonicalName() const
return m_contract.annotation().canonicalName;
}

MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) const
MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const* _contract) const
{
MemberList::MemberMap members;
if (m_super)
Expand Down Expand Up @@ -1660,7 +1660,9 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) con
&it.second->declaration()
));
}
addNonConflictingAddressMembers(members);
// In 0.5.0 address members are not populated into the contract.
if (!_contract->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050))
addNonConflictingAddressMembers(members);
return members;
}

Expand Down
58 changes: 58 additions & 0 deletions test/libsolidity/SolidityNameAndTypeResolution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7066,6 +7066,64 @@ BOOST_AUTO_TEST_CASE(array_length_validation)
CHECK_ERROR(text, TypeError, "Invalid array length, expected integer literal.");
}

BOOST_AUTO_TEST_CASE(no_address_members_on_contract)
{
char const* text = R"(
pragma experimental "v0.5.0";
contract C {
function f() {
this.balance;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"balance\" not found or not visible after argument-dependent lookup in contract");
text = R"(
pragma experimental "v0.5.0";
contract C {
function f() {
this.transfer;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"transfer\" not found or not visible after argument-dependent lookup in contract");
text = R"(
pragma experimental "v0.5.0";
contract C {
function f() {
this.send;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"send\" not found or not visible after argument-dependent lookup in contract");
text = R"(
pragma experimental "v0.5.0";
contract C {
function f() {
this.call;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"call\" not found or not visible after argument-dependent lookup in contract");
text = R"(
pragma experimental "v0.5.0";
contract C {
function f() {
this.callcode;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"callcode\" not found or not visible after argument-dependent lookup in contract");
text = R"(
pragma experimental "v0.5.0";
contract C {
function f() {
this.delegatecall;
}
}
)";
CHECK_ERROR(text, TypeError, "Member \"delegatecall\" not found or not visible after argument-dependent lookup in contract");
}

BOOST_AUTO_TEST_SUITE_END()

}
Expand Down

0 comments on commit f734305

Please sign in to comment.