aboutsummaryrefslogtreecommitdiffstats
path: root/libsolidity
diff options
context:
space:
mode:
authorchriseth <chris@ethereum.org>2017-09-29 16:23:56 +0800
committerGitHub <noreply@github.com>2017-09-29 16:23:56 +0800
commitb92184688002c73fece4e8beb0beaa897649de4e (patch)
treef6b93119c1ae7934a38fbc6246af6a5fd817be64 /libsolidity
parent010189d58eca560dd319aab07daa43bda0911a40 (diff)
parentd5d1a08b09bec098851afc48fc0f115eac193955 (diff)
downloaddexon-solidity-b92184688002c73fece4e8beb0beaa897649de4e.tar.gz
dexon-solidity-b92184688002c73fece4e8beb0beaa897649de4e.tar.zst
dexon-solidity-b92184688002c73fece4e8beb0beaa897649de4e.zip
Merge pull request #2936 from ethereum/proper-address-overload-resolution
Fix overload resolution when conflict is with members of address
Diffstat (limited to 'libsolidity')
-rw-r--r--libsolidity/ast/Types.cpp39
-rw-r--r--libsolidity/ast/Types.h2
2 files changed, 39 insertions, 2 deletions
diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp
index ebf2cd8b..a39b5775 100644
--- a/libsolidity/ast/Types.cpp
+++ b/libsolidity/ast/Types.cpp
@@ -1618,8 +1618,7 @@ string ContractType::canonicalName() const
MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) const
{
- // All address members and all interface functions
- MemberList::MemberMap members(IntegerType(160, IntegerType::Modifier::Address).nativeMembers(nullptr));
+ MemberList::MemberMap members;
if (m_super)
{
// add the most derived of all functions which are visible in derived contracts
@@ -1661,9 +1660,45 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) con
&it.second->declaration()
));
}
+ addNonConflictingAddressMembers(members);
return members;
}
+void ContractType::addNonConflictingAddressMembers(MemberList::MemberMap& _members)
+{
+ MemberList::MemberMap addressMembers = IntegerType(160, IntegerType::Modifier::Address).nativeMembers(nullptr);
+ for (auto const& addressMember: addressMembers)
+ {
+ bool clash = false;
+ for (auto const& member: _members)
+ {
+ if (
+ member.name == addressMember.name &&
+ (
+ // Members with different types are not allowed
+ member.type->category() != addressMember.type->category() ||
+ // Members must overload functions without clash
+ (
+ member.type->category() == Type::Category::Function &&
+ dynamic_cast<FunctionType const&>(*member.type).hasEqualArgumentTypes(dynamic_cast<FunctionType const&>(*addressMember.type))
+ )
+ )
+ )
+ {
+ clash = true;
+ break;
+ }
+ }
+
+ if (!clash)
+ _members.push_back(MemberList::Member(
+ addressMember.name,
+ addressMember.type,
+ addressMember.declaration
+ ));
+ }
+}
+
shared_ptr<FunctionType const> const& ContractType::newExpressionType() const
{
if (!m_constructorType)
diff --git a/libsolidity/ast/Types.h b/libsolidity/ast/Types.h
index 8ba55521..ce29975e 100644
--- a/libsolidity/ast/Types.h
+++ b/libsolidity/ast/Types.h
@@ -716,6 +716,8 @@ public:
std::vector<std::tuple<VariableDeclaration const*, u256, unsigned>> stateVariables() const;
private:
+ static void addNonConflictingAddressMembers(MemberList::MemberMap& _members);
+
ContractDefinition const& m_contract;
/// If true, it is the "super" type of the current contract, i.e. it contains only inherited
/// members.