From a94945dfe40c879b6c3762620987a235582ccecf Mon Sep 17 00:00:00 2001 From: chriseth Date: Wed, 18 Apr 2018 20:40:46 +0200 Subject: Improve error message for failed member lookup. --- libsolidity/analysis/TypeChecker.cpp | 27 ++++++++++++++++----------- 1 file changed, 16 insertions(+), 11 deletions(-) (limited to 'libsolidity/analysis') diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 87d69d97..72d29762 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1904,7 +1904,8 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) // Retrieve the types of the arguments if this is used to call a function. auto const& argumentTypes = _memberAccess.annotation().argumentTypes; MemberList::MemberMap possibleMembers = exprType->members(m_scope).membersByName(memberName); - if (possibleMembers.size() > 1 && argumentTypes) + size_t const initialMemberCount = possibleMembers.size(); + if (initialMemberCount > 1 && argumentTypes) { // do overload resolution for (auto it = possibleMembers.begin(); it != possibleMembers.end();) @@ -1918,17 +1919,21 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) } if (possibleMembers.size() == 0) { - auto storageType = ReferenceType::copyForLocationIfReference( - DataLocation::Storage, - exprType - ); - if (!storageType->members(m_scope).membersByName(memberName).empty()) - m_errorReporter.fatalTypeError( - _memberAccess.location(), - "Member \"" + memberName + "\" is not available in " + - exprType->toString() + - " outside of storage." + if (initialMemberCount == 0) + { + // Try to see if the member was removed because it is only available for storage types. + auto storageType = ReferenceType::copyForLocationIfReference( + DataLocation::Storage, + exprType ); + if (!storageType->members(m_scope).membersByName(memberName).empty()) + m_errorReporter.fatalTypeError( + _memberAccess.location(), + "Member \"" + memberName + "\" is not available in " + + exprType->toString() + + " outside of storage." + ); + } m_errorReporter.fatalTypeError( _memberAccess.location(), "Member \"" + memberName + "\" not found or not visible " -- cgit v1.2.3