From 563e0fc9a71be8beccc9aa0e3d0ba230ee3ddc0c Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Tue, 17 Jul 2018 13:31:21 +0100 Subject: Add suggestion to error message --- libsolidity/analysis/TypeChecker.cpp | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) (limited to 'libsolidity/analysis') diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index 92e5c978..fc5a3608 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1930,6 +1930,9 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) else ++it; } + + auto& annotation = _memberAccess.annotation(); + if (possibleMembers.size() == 0) { if (initialMemberCount == 0) @@ -1947,11 +1950,20 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) " outside of storage." ); } + string errorMsg = "Member \"" + memberName + "\" not found or not visible " + "after argument-dependent lookup in " + exprType->toString() + + (memberName == "value" ? " - did you forget the \"payable\" modifier?" : "."); + if (exprType->category() == Type::Category::Contract) + for (auto const& addressMember: IntegerType(160, IntegerType::Modifier::Address).nativeMembers(nullptr)) + if (addressMember.name == memberName) + { + Identifier const& var = dynamic_cast(_memberAccess.expression()); + errorMsg += " Use \"address(" + var.name() + ")." + memberName + "\" to access this address member."; + break; + } m_errorReporter.fatalTypeError( _memberAccess.location(), - "Member \"" + memberName + "\" not found or not visible " - "after argument-dependent lookup in " + exprType->toString() + - (memberName == "value" ? " - did you forget the \"payable\" modifier?" : ".") + errorMsg ); } else if (possibleMembers.size() > 1) @@ -1962,7 +1974,6 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) (memberName == "value" ? " - did you forget the \"payable\" modifier?" : ".") ); - auto& annotation = _memberAccess.annotation(); annotation.referencedDeclaration = possibleMembers.front().declaration; annotation.type = possibleMembers.front().type; @@ -1995,20 +2006,6 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) if (exprType->category() == Type::Category::Contract) { - // Warn about using address members on contracts - bool v050 = m_scope->sourceUnit().annotation().experimentalFeatures.count(ExperimentalFeature::V050); - for (auto const& addressMember: IntegerType(160, IntegerType::Modifier::Address).nativeMembers(nullptr)) - if (addressMember.name == memberName && *annotation.type == *addressMember.type) - { - solAssert(!v050, "Address member still present on contract in v0.5.0."); - m_errorReporter.warning( - _memberAccess.location(), - "Using contract member \"" + memberName +"\" inherited from the address type is deprecated." + - " Convert the contract to \"address\" type to access the member," - " for example use \"address(contract)." + memberName + "\" instead." - ); - } - // Warn about using send or transfer with a non-payable fallback function. if (auto callType = dynamic_cast(type(_memberAccess).get())) { -- cgit From faa9c221d41c45e12411c654919f318f6e7fc98f Mon Sep 17 00:00:00 2001 From: Leonardo Alt Date: Wed, 18 Jul 2018 19:51:24 +0200 Subject: Changes in ExpressionCompiler --- libsolidity/analysis/TypeChecker.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'libsolidity/analysis') diff --git a/libsolidity/analysis/TypeChecker.cpp b/libsolidity/analysis/TypeChecker.cpp index fc5a3608..8536e934 100644 --- a/libsolidity/analysis/TypeChecker.cpp +++ b/libsolidity/analysis/TypeChecker.cpp @@ -1957,8 +1957,9 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess) for (auto const& addressMember: IntegerType(160, IntegerType::Modifier::Address).nativeMembers(nullptr)) if (addressMember.name == memberName) { - Identifier const& var = dynamic_cast(_memberAccess.expression()); - errorMsg += " Use \"address(" + var.name() + ")." + memberName + "\" to access this address member."; + Identifier const* var = dynamic_cast(&_memberAccess.expression()); + string varName = var ? var->name() : "..."; + errorMsg += " Use \"address(" + varName + ")." + memberName + "\" to access this address member."; break; } m_errorReporter.fatalTypeError( -- cgit