diff options
author | Alex Beregszaszi <alex@rtfs.hu> | 2017-09-25 19:58:32 +0800 |
---|---|---|
committer | Alex Beregszaszi <alex@rtfs.hu> | 2017-09-28 21:53:41 +0800 |
commit | aa6de494577e18dcca228df1f206e6dcbcd47902 (patch) | |
tree | 373670ae5d48989157feeb8a937662fefd1d4c9c /libsolidity | |
parent | 7cb4d714c7e058ab764b14575fc32078a0343fbc (diff) | |
download | dexon-solidity-aa6de494577e18dcca228df1f206e6dcbcd47902.tar.gz dexon-solidity-aa6de494577e18dcca228df1f206e6dcbcd47902.tar.zst dexon-solidity-aa6de494577e18dcca228df1f206e6dcbcd47902.zip |
Simplify address overloading
Diffstat (limited to 'libsolidity')
-rw-r--r-- | libsolidity/analysis/TypeChecker.cpp | 34 | ||||
-rw-r--r-- | libsolidity/ast/Types.cpp | 35 |
2 files changed, 39 insertions, 30 deletions
diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 43a77002..43930125 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1720,34 +1720,12 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) ); } else if (possibleMembers.size() > 1) - { - // Remove builtins (i.e. not having a declaration) first - for (auto it = possibleMembers.begin(); it != possibleMembers.end();) - if ( - ( - // Overloaded functions without declaration (e.g. transfer(), send(), call(), etc.) - it->type->category() == Type::Category::Function && - !dynamic_cast<FunctionType const&>(*it->type).hasDeclaration() - ) - || - ( - // Overloaded members (e.g. balance) - it->type->category() == Type::Category::Integer && - memberName == "balance" - ) - ) - it = possibleMembers.erase(it); - else - ++it; - - if (possibleMembers.size() > 1) - m_errorReporter.fatalTypeError( - _memberAccess.location(), - "Member \"" + memberName + "\" not unique " - "after argument-dependent lookup in " + exprType->toString() + - (memberName == "value" ? " - did you forget the \"payable\" modifier?" : "") - ); - } + m_errorReporter.fatalTypeError( + _memberAccess.location(), + "Member \"" + memberName + "\" not unique " + "after argument-dependent lookup in " + exprType->toString() + + (memberName == "value" ? " - did you forget the \"payable\" modifier?" : "") + ); auto& annotation = _memberAccess.annotation(); annotation.referencedDeclaration = possibleMembers.front().declaration; diff --git a/libsolidity/ast/Types.cpp b/libsolidity/ast/Types.cpp index ebf2cd8b..1a9a374f 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,6 +1660,38 @@ MemberList::MemberMap ContractType::nativeMembers(ContractDefinition const*) con &it.second->declaration() )); } + // Add overloads from address only if there is no conflict + 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 + )); + } return members; } |