Merge pull request #5979 from ethereum/fix-context-for-hint

Make sure "value" error hint is only displayed in the right context
This commit is contained in:
chriseth 2019-02-18 17:35:31 +01:00 committed by GitHub
commit 1b6d87c5bd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 32 additions and 21 deletions

View File

@ -2046,20 +2046,24 @@ bool TypeChecker::visit(MemberAccess const& _memberAccess)
} }
string errorMsg = "Member \"" + memberName + "\" not found or not visible " string errorMsg = "Member \"" + memberName + "\" not found or not visible "
"after argument-dependent lookup in " + exprType->toString() + "."; "after argument-dependent lookup in " + exprType->toString() + ".";
if (memberName == "value")
{ if (auto const& funType = dynamic_pointer_cast<FunctionType const>(exprType))
errorMsg.pop_back();
errorMsg += " - did you forget the \"payable\" modifier?";
}
else if (auto const& funType = dynamic_pointer_cast<FunctionType const>(exprType))
{ {
auto const& t = funType->returnParameterTypes(); auto const& t = funType->returnParameterTypes();
if (t.size() == 1)
if ( if (memberName == "value")
t.front()->category() == Type::Category::Contract || {
t.front()->category() == Type::Category::Struct if (funType->kind() == FunctionType::Kind::Creation)
) errorMsg = "Constructor for " + t.front()->toString() + " must be payable for member \"value\" to be available.";
errorMsg += " Did you intend to call the function?"; else
errorMsg = "Member \"value\" is only available for payable functions.";
}
else if (
t.size() == 1 &&
(t.front()->category() == Type::Category::Struct ||
t.front()->category() == Type::Category::Contract)
)
errorMsg += " Did you intend to call the function?";
} }
else if (exprType->category() == Type::Category::Contract) else if (exprType->category() == Type::Category::Contract)
{ {

View File

@ -471,7 +471,7 @@ BOOST_AUTO_TEST_CASE(address_staticcall_value)
} }
} }
)"; )";
CHECK_ERROR(sourceCode, TypeError, "Member \"value\" not found or not visible after argument-dependent lookup"); CHECK_ERROR(sourceCode, TypeError, "Member \"value\" is only available for payable functions.");
} }
} }

View File

@ -0,0 +1,7 @@
contract C {
// Tests that we don't get a wrong error about constructors
function f() public view returns (C) { return this; }
function g() public { this.f.value(); }
}
// ----
// TypeError: (155-167): Member "value" is only available for payable functions.

View File

@ -5,4 +5,4 @@ contract C {
} }
} }
// ---- // ----
// TypeError: (94-101): Member "value" not found or not visible after argument-dependent lookup in function (uint256) external returns (uint256) - did you forget the "payable" modifier? // TypeError: (94-101): Member "value" is only available for payable functions.

View File

@ -5,4 +5,4 @@ contract test {
} }
} }
// ---- // ----
// TypeError: (87-96): Member "value" not found or not visible after argument-dependent lookup in function () - did you forget the "payable" modifier? // TypeError: (87-96): Member "value" is only available for payable functions.

View File

@ -3,4 +3,4 @@ contract test {
function f() public { (new receiver()).nopay.value(10)(); } function f() public { (new receiver()).nopay.value(10)(); }
} }
// ---- // ----
// TypeError: (91-119): Member "value" not found or not visible after argument-dependent lookup in function () external - did you forget the "payable" modifier? // TypeError: (91-119): Member "value" is only available for payable functions.

View File

@ -8,4 +8,4 @@ contract D {
} }
} }
// ---- // ----
// TypeError: (106-119): Member "value" not found or not visible after argument-dependent lookup in function () returns (contract C) - did you forget the "payable" modifier? // TypeError: (106-119): Constructor for contract C must be payable for member "value" to be available.

View File

@ -4,4 +4,4 @@ contract C {
} }
} }
// ---- // ----
// TypeError: (47-62): Member "value" not found or not visible after argument-dependent lookup in function (bytes memory) pure returns (bytes32) - did you forget the "payable" modifier? // TypeError: (47-62): Member "value" is only available for payable functions.

View File

@ -4,4 +4,4 @@ contract C {
} }
} }
// ---- // ----
// TypeError: (47-59): Member "value" not found or not visible after argument-dependent lookup in function (bytes memory) pure returns (bytes32) - did you forget the "payable" modifier? // TypeError: (47-59): Member "value" is only available for payable functions.

View File

@ -4,4 +4,4 @@ contract C {
} }
} }
// ---- // ----
// TypeError: (47-62): Member "value" not found or not visible after argument-dependent lookup in function (bytes memory) pure returns (bytes20) - did you forget the "payable" modifier? // TypeError: (47-62): Member "value" is only available for payable functions.

View File

@ -4,4 +4,4 @@ contract C {
} }
} }
// ---- // ----
// TypeError: (47-62): Member "value" not found or not visible after argument-dependent lookup in function (bytes32,uint8,bytes32,bytes32) pure returns (address) - did you forget the "payable" modifier? // TypeError: (47-62): Member "value" is only available for payable functions.